Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get plot attributes in Plots.jl

How can I access the attributes of a plot after creating it?

For example, I was hoping to get the y-axis limits from a plot. Something like this didn't work:

p1 = Plots.plot(rand(10))
get(p1,:ylim)

This errors:

MethodError: no method matching get(::Plots.Plot{Plots.GRBackend}, ::Symbol)
like image 389
Alec Avatar asked Oct 29 '25 12:10

Alec


1 Answers

Plots are organized into subplots (often just one) which are organized into series. In this case you want the y axis limits, which is a function of the subplot. Normally you can get a named attribute (e.g. y) from the first series in the first subplot by

p1[1][1][:y]

In the case of limits it's a little more complicated, they are properties of Axis which are owned by the subplot. But luckily you can just do

ylims(p1)
like image 116
Michael K. Borregaard Avatar answered Nov 01 '25 14:11

Michael K. Borregaard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!