Pandas plot method incompatibility.
Pandas plot methods seem to fail on broken axes. Here is a minimalist example:
import pandas as pd
from brokenaxes import brokenaxes
ts = pd.Series(range(10)).plot(ax=brokenaxes())
And the error traceback:
Traceback (most recent call last):
File "./baxbug.py", line 10, in <module>
ts= pd.Series(range(10)).plot(ax=brokenaxes())
File "/usr/lib/python3.7/site-packages/pandas/plotting/_core.py", line 794, in __call__
return plot_backend.plot(data, kind=kind, **kwargs)
File "/usr/lib/python3.7/site-packages/pandas/plotting/_matplotlib/__init__.py", line 62, in plot
plot_obj.generate()
File "/usr/lib/python3.7/site-packages/pandas/plotting/_matplotlib/core.py", line 281, in generate
self._make_plot()
File "/usr/lib/python3.7/site-packages/pandas/plotting/_matplotlib/core.py", line 1043, in _make_plot
if self._is_ts_plot():
File "/usr/lib/python3.7/site-packages/pandas/plotting/_matplotlib/core.py", line 1035, in _is_ts_plot
return not self.x_compat and self.use_index and self._use_dynamic_x()
File "/usr/lib/python3.7/site-packages/pandas/plotting/_matplotlib/core.py", line 1040, in _use_dynamic_x
return _use_dynamic_x(self._get_ax(0), self.data)
File "/usr/lib/python3.7/site-packages/pandas/plotting/_matplotlib/core.py", line 686, in _get_ax
ax.get_yaxis().set_visible(True)
AttributeError: 'CallCurator' object has no attribute 'get_yaxis'
On can work around the issue using brokenaxes().plot(...).
Using pandas 0.25.1 and pip-installed brokenaxes (from 18 Oct. 2019) - Thanks!
this is a tricky one. Would welcome a contribution!
Yes I've begun to notice after posting the issue, but I don't have time in the near future, sorry...
I was able to make this specific case not raise an exception by adding the following to the BrokenAxes class:
@property
def left_ax(self):
return self.axs[0]
@property
def right_ax(self):
return self.axs[0]
@property
def xaxis(self):
return self.axs[0].xaxis
as well as hacking CallCurator's __call__() method a bit:
def __call__(self, *args, **kwargs):
if self.method.startswith("get_"):
return getattr(self.broken_axes.axs[0].axes, self.method)(*args, **kwargs)
return self.broken_axes.subax_call(self.method, args, kwargs)
Then the example given in the original issue will result in a line plot. Unfortunately, as soon as you try to actually break up any of the axes, the axis limits are wrong and the line does not get fully plotted (it is only plotted into one of the subplots). But maybe it's a start?
Workarround (does not use the library, but might be interesting for others)
f, (ax, ax2) = plt.subplots(2, 1, sharex=True, gridspec_kw=dict(height_ratios= [190-180,75],hspace=.1))
ax.set_ylim(180, 190)
ax2.set_ylim(0, 75)
# plot the same data on both axes
df.plot.hist(ax=ax)
df.plot.hist(ax=ax2)
# other refinements as in the link
https://matplotlib.org/3.1.0/gallery/subplots_axes_and_figures/broken_axis.html
Yes this is more or less what brokenaxes does under the hood and this is probably the direction I would go in.
On Mon, May 11, 2020, 8:41 AM Stefan Heid [email protected] wrote:
Workarround (does not use the library, but might be interesting for others)
f, (ax, ax2) = plt.subplots(2, 1, sharex=True, gridspec_kw=dict(height_ratios= [190-180,75],hspace=.1)) ax.set_ylim(180, 190) ax2.set_ylim(0, 75)
plot the same data on both axes
df.plot.hist(ax=ax) df.plot.hist(ax=ax2)
other refinements as in the link
https://matplotlib.org/3.1.0/gallery/subplots_axes_and_figures/broken_axis.html
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bendichter/brokenaxes/issues/40#issuecomment-626676565, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGOEESZSV7H7VD2TRQCQBTRQ7W57ANCNFSM4JCGXRCQ .