KristofferC / PGFPlotsX.jl

Plots in Julia using the PGFPlots LaTeX package
Other
301 stars 40 forks source link

Changing tikz options withPGFPlotsX.Options deletes all default options, instead of just adding the new option #319

Open andresdrenik opened 1 year ago

andresdrenik commented 1 year ago

Hi,

First of all, huge thank you for this amazing package!

Here is a simple example that illustrates my issue. I'm plotting two lines in the following way:

      pgfplotsx()
      default(legendfonthalign = :left,
              xtickfontsize = 18,
              ytickfontsize = 18,
              legendfontsize = 18,
              xlabelfontsize = 18,
              ylabelfontsize = 18,
              markersize = 10,
              linewidth = 3,
              size = (600, 400))

      y = rand(100,2)
      plot(y, legend=:topright)

Sometimes my legendfontsize needs to be large, but then the labels start overlaping with each other. In Tikz one can fix this by increasing the gap between the labels by adding {row sep={2.5pt}} inside legend style set of options. This can be easily done in my previous example with

plot(y, legend=:topright, legend_style = PGFPlotsX.Options("row sep" =>"2.5pt"),extra_kwargs = :subplot)

Now, when I save my tikz figure I do see the new option. The problem is that

legend_style = PGFPlotsX.Options("row sep" =>"2.5pt"),extra_kwargs = :subplot

deletes all my legend options (the default ones by Tikz and the ones I specify in default()). It'd be great if there was a way to just add an option, while keeping the default ones.

Thanks again!

KristofferC commented 1 year ago

It is unclear if this is an issue in Plots using this as a backend or in this package. Do you have a repro that only uses PGFPlotsX?

andresdrenik commented 1 year ago

I'm fairly new to PGFPlotsX, but please let me know what you'd like to see and I can come up with an example that only uses PGFPlotsX.

KristofferC commented 1 year ago

Something that shows a bug in PGFPlotsX.jl :)

andresdrenik commented 1 year ago

I'm not sure how to do that. By definition, when you create a plot with PGFPlotsX, you need to specify all the options yourself. In that case, when creating the plot, I'd manually write all the default options behind plot(y, legend=:topright) and I'd also add "row sep" =>"2.5pt" to legend_style. This method should definitely work and should not reveal any bug.

Alternatively, is there a way to create a plot with the pgfplotsx() backend (e.g., my simple plot(y, legend=:topright)) and then modify an option with push/merge/append (as https://kristofferc.github.io/PGFPlotsX.jl/stable/man/options/)? Or somehow "convert" the p1 = plot(...) object into pgfplotsx so that options can be later modified?

BeastyBlacksmith commented 11 months ago

You can via Plots.backend_object(plot(1:5)).the_plot though I should probably make that return the plot object already