# How to link the x-axis of subplots using Plots?

**URL:** https://discourse.julialang.org/t/how-to-link-the-x-axis-of-subplots-using-plots/68906
**Category:** General Usage
**Tags:** plotting, plots, plotlyjs
**Created:** [September 29, 2021, 6:58am UTC](https://discourse.julialang.org/t/how-to-link-the-x-axis-of-subplots-using-plots/68906 "2021-09-29T06:58:34Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)
#### Post date: [September 29, 2021, 6:58am UTC](https://discourse.julialang.org/t/how-to-link-the-x-axis-of-subplots-using-plots/68906/1 "2021-09-29T06:58:34Z")

</div>

Essential for zooming in subplots. The command in Matlab is

> linkaxes(subplots, ‘x’);

Plot, then zoom, without “link”:

```julia
using Plots
plotlyjs()
plot(rand(100, 4), layout = (4, 1))

```

 ![Capture](https://global.discourse-cdn.com/julialang/original/3X/b/c/bc27eafea6a092f9a11425d7bb1bdf42e1ca3cfd.png)

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [September 29, 2021, 9:12am UTC](https://discourse.julialang.org/t/how-to-link-the-x-axis-of-subplots-using-plots/68906/2 "2021-09-29T09:12:01Z")

</div>

That is the role of plots argument ` link=:x`

---

<div class="post-metadata">

### Author: ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)
#### Post date: [September 29, 2021, 9:17am UTC](https://discourse.julialang.org/t/how-to-link-the-x-axis-of-subplots-using-plots/68906/3 "2021-09-29T09:17:12Z")

</div>

Thx, this time I can not blame the [search](https://docs.juliaplots.org/latest/search/?q=link).

While we are here, how to have the above subplots show different colors as in a combined plot?

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [September 29, 2021, 9:35am UTC](https://discourse.julialang.org/t/how-to-link-the-x-axis-of-subplots-using-plots/68906/4 "2021-09-29T09:35:56Z")

</div>

if you have 4 curves add plot argument: `color=[:red :blue :green :orange]` for example.

---

<div class="post-metadata">

### Author: ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)
#### Post date: [October 3, 2021, 5:35pm UTC](https://discourse.julialang.org/t/how-to-link-the-x-axis-of-subplots-using-plots/68906/5 "2021-10-03T17:35:39Z")

</div>

Good idea, extended it to a cycling color palette in  
[makie\_subplots](https://discourse.julialang.org/t/makie-multiline-plots-subplots-and-attributes-examples/69113).  
Makie gets you fine-grain control of your plots.
