JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.84k stars 355 forks source link

How to access internal plot attributes with arbitrary to add arrows at the end of axis #1966

Open aborzunov opened 5 years ago

aborzunov commented 5 years ago

This is kind of duplication of #1348

In matplotlib it is possible to set arrows at the end of axis with smth like ax.axis["xzero"].set_axisline_style("-|>") see full example

I tried

julia> fig = plot(randn(10))

julia> fig.series_list[1][:subplot].o."axis"
PyObject <bound method Axes.axis of <matplotlib.axes._axes.Axes object at 0x24bc85c10>>

But this leads me to bound method, not to

>>> from mpl_toolkits.axisartist.axislines import SubplotZero
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> fig = plt.figure(1)
>>> ax = SubplotZero(fig, 111)
>>> fig.add_subplot(ax)
<matplotlib.axes._subplots.AxesZeroSubplot object at 0x11aac2550>
>>> ax.axis
{u'right': <mpl_toolkits.axisartist.axis_artist.AxisArtist object at 0x11ab06d50>, u'bottom': <mpl_toolkits.axisartist.axis_artist.AxisArtist object at 0x11aafa890>, u'top': <mpl_toolkits.axisartist.axis_artist.AxisArtist object at 0x11ab06050>, u'xzero': <mpl_toolkits.axisartist.axis_artist.AxisArtist object at 0x11ab12390>, u'yzero': <mpl_toolkits.axisartist.axis_artist.AxisArtist object at 0x11ab12c10>, u'left': <mpl_toolkits.axisartist.axis_artist.AxisArtist object at 0x11ab066d0>}

Obviously, it is because i cant call SubplotZero from mpl_toolkits.axisartist.axislines. Is there a way to execute equivalent of this python code at my figure Plots.Plot{Plots.PyPlotBackend}?

H-M-H commented 5 years ago

Once you access the .o attribute you need to have a look at the documentation of the respective backend used for plotting. In this case PyPlot which then tells you to look up the matplotlib docs :P.

Interaction can be done like this:

julia> p = plot(-1:0.1:1 ,x->exp(-1/(1-x^2)), xlab="X")

julia> p.series_list[1][:subplot].o.axes.xaxis.get_label()
PyObject Text(0.5, 13.761945538057772, 'X')
# or like this
julia> p.o.axes[1].xaxis.get_label()
PyObject Text(0.5, 13.761945538057772, 'X')

Unfortunately the solution you are describing above makes use of a non standard class for axes/axis: https://matplotlib.org/api/_as_gen/mpl_toolkits.axisartist.axislines.html. Thus the method set_axisline_style is not available as it does not belong to the standard axis class.