Plots
is simple and effective, but sometimes I would like to have a little control over individual elements of the plot in order to fine-tune its appearance.
Is it possible to directly update the backend plot object?
For example, for the default backend pyplot
I tried
using Plots p = plot(sin) po[:axes][1][:xaxis][:set_ticks_position]("top")
but the schedule does not change. Calling po[:show]()
subsequently also does not help.
In other words: is there a way to use the pyplot
interface for a plot that was originally created using Plots
?
Edit:
Changes to the pyplot
object become visible (also in gui) when saving the picture:
using Plots using PyPlot p = Plots.plot(sin, top_margin=1cm) gui() # not needed when using the REPL gca()[:xaxis][:set_ticks_position]("top") PyPlot.savefig("test.png")
Here I used po[:axes][1] == gca()
. You need to set top_margin=1cm
, because the graph area is not automatically configured (it doesnβt matter for my actual fine tuning).
This also works for future updates if only the pyplot
interface is pyplot
. For example, after the following commands, the chart will have a red right border in addition to the labels at the top:
gca()[:spines]["right"][:set_color]("red") PyPlot.savefig("test.png")
However, when using the Plots
command, such as plot!(xlabel="foo")
, all previous changes made with pyplot
are overwritten (which is not a surprise).
The question remains how to update gui interactively without explicitly calling PyPlot.savefig
.