Access backend functionality with Julia stories

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 .

+6
source share
2 answers

No - the plot is a Plots object, not a PyPlot object. In your specific example, you can do plot(sin, xmirror = true ).

+1
source

I am trying to do the same, but have not found a solution to update an existing plot. But here is a partial answer: you can request information from the PyPlot axis object

 julia> Plots.plot(sin, 1:4) julia> Plots.PyPlot.plt[:xlim]() (1.0,4.0) julia> Plots.plot(sin, 20:24) julia> ax = Plots.PyPlot.plt[:xlim]() (20.0,24.0) 

and it is being updated.

+1
source

Source: https://habr.com/ru/post/1015627/


All Articles