Plots.jl: multiple plots in same subplot

plotting

#1

The documentation 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

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?


#2

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:

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

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

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 - 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.


#3

I am sorry: I wanted to mention your post 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.


#4

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.


#5

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.