# Plots.jl: multiple plots in same subplot

**URL:** <https://discourse.julialang.org/t/plots-jl-multiple-plots-in-same-subplot/602>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [November 28, 2016, 5:13am UTC](https://discourse.julialang.org/t/plots-jl-multiple-plots-in-same-subplot/602 "2016-11-28T05:13:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [November 28, 2016, 5:13am UTC](https://discourse.julialang.org/t/plots-jl-multiple-plots-in-same-subplot/602/1 "2016-11-28T05:13:12Z")

</div>

The [documentation](https://juliaplots.github.io/basics/) has several examples of how to plot several traces of the **same** length on either the same or different plots and it is easier to overlook the fact that one can modify an existing plot also with the command as stated at the top of the page linked above

```julia
plot!(plt, args...; kw...) # modifies Plot `plt`

```

Also, if `p1`, `p2`, …, `pn` are plots, `plot(p1, p2, ..., pn)` will plot them with a default layout.

For as much as this sound ridiculous, not knowing this was my only reason to stay clear of Plots.jl.

A question: what is the reason not to throw an error when plotting `plot(x,y)` with `x` and `y` of different length, but to wrap the data around?

---

<div class="post-metadata">

**Author:** ![swt30](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/swt30/32/4667_2.png) [@swt30](https://discourse.julialang.org/u/swt30)\
**Post date:** [November 28, 2016, 10:36am UTC](https://discourse.julialang.org/t/plots-jl-multiple-plots-in-same-subplot/602/2 "2016-11-28T10:36:47Z")

</div>

My understanding is that Plots automatically cycles/broadcasts _everything_ to fit (not just x and y values). It’s not so useful for the x and y values, but for other attributes it’s very handy. For example, you can alternate between solid and dashed lines like this:

```julia
using Plots
plot(randn(10, 4), linestyle=[:solid :dash])

```

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

You might also find it useful to know that you can manipulate subplots in a layout too:

```julia
plot!(p[n], ...) # modifies the nth subplot of p
plot!(p[a,b], ...) # modifies the subplot in grid position [a,b])

```

You could take a look at [ExamplePlots.jl](http://github.com/tbreloff/ExamplePlots.jl) - if there’s anything that you think deserves a clear example, I’m sure it would fit well in there. I told @tbreloff I’d put together an example of some of the layout stuff you mentioned, like `plot(p1, p2, ..., pn)` to compose plots, so I’d better get on that at some stage.

---

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [November 28, 2016, 11:50am UTC](https://discourse.julialang.org/t/plots-jl-multiple-plots-in-same-subplot/602/3 "2016-11-28T11:50:00Z")

</div>

I am sorry: I wanted to mention [your post](https://groups.google.com/d/msg/julia-users/GBIc0jTCug8/7ooegkC2BAAJ) which I found useful to understand `@layout`. (Thank you for the other commands too.)

The official documentation contains fancy examples for advanced users. I am a simple user and I had a hard time understanding for instance how to plot 4 traces of different length in 4 different subplots, until I came across your notebook. The official documentation (including the _basic_ concepts section) has only examples of sets of equal length data, probably because Tom wants to advertise the fact that one can generate many plots with one single command. I find myself more often in the situation of plotting traces of different lengths and going back to the plots to add other traces.

---

<div class="post-metadata">

**Author:** ![swt30](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/swt30/32/4667_2.png) [@swt30](https://discourse.julialang.org/u/swt30)\
**Post date:** [November 28, 2016, 12:35pm UTC](https://discourse.julialang.org/t/plots-jl-multiple-plots-in-same-subplot/602/4 "2016-11-28T12:35:24Z")

</div>

I agree, it sounds like we could use some more basic examples of multiple plots that don’t assume equal-length traces. That’s helpful to know.

---

<div class="post-metadata">

**Author:** ![tbreloff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbreloff/32/68_2.png) [@tbreloff](https://discourse.julialang.org/u/tbreloff)\
**Post date:** [November 28, 2016, 1:34pm UTC](https://discourse.julialang.org/t/plots-jl-multiple-plots-in-same-subplot/602/5 "2016-11-28T13:34:42Z")

</div>

I agree that a “common plots” page is a good thing. That was the intention  
of the examples pages in the docs. For new people that are looking for ways  
to contribute, the best thing would be to open an issue with some  
well-thought-out ideas of examples and/or doc pages to add. Or make a  
tutorial notebook on a part of Plots which you find confusing, and I can  
reorganize ExamplePlots to highlight the tutorials. Note: even adding a  
non-functioning notebook that describes what you want might help, so  
someone can just fill in the commands.

Tl;dr I am too deep in Plots to know what is intuitive and what is horribly  
confusing. I need your help.
