Confidence interval with Plots and pgfplots()

@BeastyBlacksmith , I managed to install everything, it seems. But ribbon is still not defined. Can you replicate the code I initially posted at the top of this page?

Sorry, the code was indeed broken. The fix will come with the next release.
Or you can use

add https://github.com/BeastyBlacksmith/Plots.jl#pgfplotsx

if you need it now.
Note, that if you intended to give different ribbon size in +y- and -y-direction, that this is currently not supported by Plots as you may have noticed when using the PyPlot backend.

1 Like

I correct myself: Asymmetric ribbons are supported and the syntax is

plot( x, y, ribbon=(dy-, dy+))

yes, the ribbon can be asymmetric, and this is great. I don’t know if this is supposed to be this way, but just running

aa = rand(10)
plot(collect(1:10),aa)

plots the entire area between the graph and some straight line, instead of drawing just a simple line. I am happy to get into the details from a manual, but this seems kind of weird.

Thanks for reporting that bug. That is also fixed on my branch now and comes with next release ( if you are on that branch you can get the fix by ] up ).

great. the last step (which is being surprisingly hard to understand looking at the documentation of PGFPlotsX.jl) is running it on latex.
I run

tt = collect(1:10)
plot(tt,tt.^2)
savefig("folders/myfile.tex")

Which packages do I need in the preamble to be able to \input{myfile.tex}?

It seems that what creates problem is that the figure creates this
\begin{tikzpicture}[/tikz/background rectangle/.style={fill={rgb,1:red,1.0;green,1.0;blue,1.0}, draw opacity={1.0}}, show background rectangle].
The part in [/tikz/background rectangle…] is the part that creates problem. Once it is removed the figure is plotted without problems.

Other bugs:

  1. When you run plot and then overlay plot! multiple times, you need to run the ribbon last or it messes the legend
  2. @layout doesn’t work well. l = @layout [ a b; c d ] stuck the plots one below each other or it even overlaps two plots
  3. xaxis!(…) is not added to the plot unless it is run together with the plot

thanks again for managing this package, it produced awesome plots

1 Like

you either can get a standalone version by plot(tt, tt.^2, tex_output_standalone = true) or you can query the preamble by Plots.pgfx_preamble( plot ).
Will have a look at the other issues during the week. ( The layouting is already in the meta-issue, but right now I don’t have a good solution). If you want a 2x2 Grid layout = 4 should work. And you can increase margins by setting left/right/top/bottom_margin if you have overlaps.
Hope, this helps in the meantime.

1 Like

Where should I type “Plots.pgfx_preamble( plot )”? Does it remove the problematic part next to \begin{tikzpicture} or does it make that part no longer problematic?

By reading a lot of the pyplot() blogs it seems that the accepted solution for multiple levels of plots and labels is creating empty plots with only a title and to stack them all together. This solution does not work well with pgfplotsx(). In particular, the empty plot still draws the ticks in the x and y-axis.

Also, some marker types like star5 do not get colored: they appear light gray no matter which marker color is chosen.

I would suggest typing it at the REPL and will give you the code that needs to be put before \begin{document} in the LaTeX file in order for the plot to work as written in the tikzpicture environment. So execute the command where plot is a name for a plot object like e.g. plot = Plots.plot(1:5) ( choose a better name than me ^^;).

I don’t really get, what you are trying to do here. Can you give me the series of commands you ran and what your expected outcome is?

That is fixed on my branch now.

Here is an example

plot1 = scatter(rand(10),rand(10))
plot2 = scatter(rand(10),rand(10))
subtitle1 = plot(title = "Subtitle1", grid = false, showaxis = false, bottom_margin = -10Plots.px,top_margin = 1Plots.px)
subtitle2 = plot(title = "Subtitle2", grid = false, showaxis = false, bottom_margin = -10Plots.px,top_margin = 1Plots.px)
title = plot(title = "Title", grid = false, showaxis = false, bottom_margin = -10Plots.px,top_margin = 1Plots.px)
l = @layout [  a{0.01h}; b{0.1h,0.5w} c{0.1h,0.5w}; d{1h,0.5w} e{1h,0.5w} ]
plot(title,subtitle1,subtitle2,plot1,plot2,layout = l,size=(3000,10000))

What this should do is plotting plot1 and plot2 next to each, put subtitle1 and subtitle2 on top of each and title in the middle on top of the figure.

This is a workaround in the pyplot() world, but of course it would be great if there was a less convoluted way of having layers of titles

So at the end you want something like this, if I got you right.
So the longterm solution will probably be to make Plots more transparent for the backend, such that you could add that node entry by hand. And maybe I should think about implementing the layouting in terms of nodes instead of groupplots anyway.
For now (and likely at least until March next year) using the @layout macro won’t work with the pgfplotsx-backend.

Also consider postprocessing the latex file, if you include it in a LaTeX document anyway.

1 Like

Yes, post processing is an option but I think there is a huge benefit from not having to touch the code. Let me ask a quick question.

what is the way you recommend for having 2 plots next to each other, each with a title, and then an overall title for the picture? This seems an important starting point to me.

A small detail:
in yerror the CI are black, but the horizontal ticks at the extremes of the CI are transparent. It would be nice if they were the same color as the marker used for the point estimate (like in pyplot()). Please let me know if this is not clear.

I can’t confirm that. Try scatter(1:5, marker=:star5, markerstrokecolor = :red).
I also don’t see the yerror issue, can you provide a MWE?