rgerum / pylustrator

Visualisations of data are at the core of every publication of scientific research results. They have to be as clear as possible to facilitate the communication of research. As data can have different formats and shapes, the visualisations often have to be adapted to reflect the data as well as possible. We developed Pylustrator, an interface to directly edit python generated matplotlib graphs to finalize them for publication. Therefore, subplots can be resized and dragged around by the mouse, text and annotations can be added. The changes can be saved to the initial plot file as python code.
GNU General Public License v3.0
706 stars 38 forks source link

twinx() seems to blow up matplotlib when pylustrator switched on - 'AxesSubplot' object has no attribute 'collections' #20

Closed derketo closed 1 year ago

derketo commented 4 years ago

Not sure how, but turning on pylustrator causes matplotlib error without any reference in stack trace to pylustrator. Presumably something is being overridden or set in pylustrator.start() which causes matplotlib behaviour changes which are causing this.

My code working fine without pylustrator (but could be refined :):

chart_some_data.py

# various other imports omitted

import datetime import matplotlib.dates as mpdts import pylustrator

#pylustrator.start() # works with this commented out

# ... omitted data collation, which creates w_dts and w_pps as identical length vectors # w_pps are floats, w_dts are floats from datetimes using mpdts.date2num() # ... fig, axs=plt.subplots(nrows=2, ncols=1) axs[0].plot(w_dts, w_pps) ax0_2=axs[0].twinx()

Uncomment the 'pylustrator.start()' line, and matplotlib blows up as follows (cannot get this editor to show the indents on the alternate code lines, sorry):

File "...\dev\chart_some_data.py", line 57, in <module> ax0_2=axs[0].twinx() File "...\Lib\site-packages\matplotlib\axes\_base.py", line 4402, in twinx ax2 = self._make_twin_axes(sharex=self) File "...\Lib\site-packages\matplotlib\axes\_subplots.py", line 191, in _make_twin_axes self.get_subplotspec(), *args, label=sentinel, **kwargs) File "...\Lib\site-packages\matplotlib\figure.py", line 1419, in add_subplot a = subplot_class_factory(projection_class)(self, *args, **kwargs) File "...\Lib\site-packages\matplotlib\axes\_subplots.py", line 76, in __init__ self._axes_class.__init__(self, fig, self.figbox, **kwargs) File "...\Lib\site-packages\matplotlib\axes\_base.py", line 454, in __init__ self.cla() File "...\Lib\site-packages\matplotlib\axes\_base.py", line 975, in cla x0, x1 = self._sharex.get_xlim() File "...\Lib\site-packages\matplotlib\axes\_base.py", line 3085, in get_xlim return tuple(self.viewLim.intervalx) File "...\Lib\site-packages\matplotlib\axes\_base.py", line 599, in viewLim self._unstale_viewLim() File "...\Lib\site-packages\matplotlib\axes\_base.py", line 595, in _unstale_viewLim self.autoscale_view(scalex=scalex, scaley=scaley) File "...\Lib\site-packages\matplotlib\axes\_base.py", line 2384, in autoscale_view for ax in self._shared_x_axes.get_siblings(self) File "...\Lib\site-packages\matplotlib\axes\_base.py", line 2386, in <listcomp> for artist in ax.get_children()])) File "...\Lib\site-packages\matplotlib\axes\_base.py", line 4218, in get_children *self.collections,

builtins.AttributeError: 'AxesSubplot' object has no attribute 'collections'

rgerum commented 4 years ago

I cannot reproduce the error. Here it works fine. Maybe you can update to the latest version and try again. Maybe its a problem with the datetime objects. But then I would be grateful to have a full working minimal example.

rgerum commented 1 year ago

As I did not receive feedback on how to reproduce this bug I will close the issue for now.