Repository navigation
Description
Bug summary
The figure manager is None even though everything should work nicely.
Code for reproduction
A simple example of pandas should suffice:
import pandas as pd
df = pd.DataFrame({'lab':['A', 'B', 'C'], 'val':[10, 30, 20]})
ax = df.plot.bar(x='lab', y='val', rot=0)Actual outcome
Out of the sudden, my server CI fails with the following traceback:
File ~/work/conflowgen/conflowgen/conflowgen/analyses/inbound_and_outbound_vehicle_capacity_analysis_report.py:77, in InboundAndOutboundVehicleCapacityAnalysisReport.get_report_as_graph(self, **kwargs)
71 df = pd.DataFrame({
72 "inbound volume (in TEU)": inbound_capacities,
73 "outbound volume (in TEU)": outbound_actual_capacities,
74 "outbound maximum capacity": outbound_maximum_capacities
75 })
76 df.index = [str(i).replace("_", " ") for i in df.index]
---> 77 ax = df.plot.barh()
78 ax.set_xlabel("Capacity (in TEU)")
79 ax.set_title("Inbound and outbound vehicle capacity analysis")
File ~/.local/lib/python3.8/site-packages/pandas/plotting/_core.py:1217, in PlotAccessor.barh(self, x, y, **kwargs)
1133 @Appender(
1134 """
1135 See Also
(...)
1206 @Appender(_bar_or_line_doc)
1207 def barh(self, x=None, y=None, **kwargs):
1208 """
1209 Make a horizontal bar plot.
1210
(...)
1215 other axis represents a measured value.
1216 """
-> 1217 return self(kind="barh", x=x, y=y, **kwargs)
File ~/.local/lib/python3.8/site-packages/pandas/plotting/_core.py:972, in PlotAccessor.__call__(self, *args, **kwargs)
969 label_name = label_kw or data.columns
970 data.columns = label_name
--> 972 return plot_backend.plot(data, kind=kind, **kwargs)
File ~/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/__init__.py:71, in plot(data, kind, **kwargs)
69 kwargs["ax"] = getattr(ax, "left_ax", ax)
70 plot_obj = PLOT_CLASSES[kind](data, **kwargs)
---> 71 plot_obj.generate()
72 plot_obj.draw()
73 return plot_obj.result
File ~/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py:328, in MPLPlot.generate(self)
326 self._args_adjust()
327 self._compute_plot_data()
--> 328 self._setup_subplots()
329 self._make_plot()
330 self._add_table()
File ~/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py:386, in MPLPlot._setup_subplots(self)
384 else:
385 if self.ax is None:
--> 386 fig = self.plt.figure(figsize=self.figsize)
387 axes = fig.add_subplot(111)
388 else:
File ~/.local/lib/python3.8/site-packages/matplotlib/pyplot.py:810, in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, clear, **kwargs)
798 _api.warn_external(
799 f"More than {max_open_warning} figures have been opened. "
800 f"Figures created through the pyplot interface "
(...)
803 f"warning, see the rcParam `figure.max_open_warning`).",
804 RuntimeWarning)
806 manager = new_figure_manager(
807 num, figsize=figsize, dpi=dpi,
808 facecolor=facecolor, edgecolor=edgecolor, frameon=frameon,
809 FigureClass=FigureClass, **kwargs)
--> 810 fig = manager.canvas.figure
811 if fig_label:
812 fig.set_label(fig_label)
AttributeError: 'NoneType' object has no attribute 'canvas'
AttributeError: 'NoneType' object has no attribute 'canvas'
The first invocation is just some default invocation of pandas. Thus, I am very confident that this has nothing to do with my code. Just a few days back, the CI was working wonderfully. It is still working wonderfully locally on my computer.
Expected outcome
The figures should be displayed just like before.
Additional information
See https://github.com/1kastner/conflowgen/runs/7882122350?check_suite_focus=true for the original traceback.
It has worked before.
I have no idea why this is happening now. I was even tampering with the matplotlib backend (setting one explicitely via an env variable) but it did not have any effect on this error.
Operating system
Linux
Matplotlib Version
3.5.3
Matplotlib Backend
agg
Python version
3.10.6
Jupyter version
No response
Installation
pip
Activity
[-][Bug]: AttributeError: 'NoneType' object has no attribute 'canvas'[/-][+][Bug]: F8gure manager is gone - AttributeError: 'NoneType' object has no attribute 'canvas'[/+][-][Bug]: F8gure manager is gone - AttributeError: 'NoneType' object has no attribute 'canvas'[/-][+][Bug]: Figure manager is gone - AttributeError: 'NoneType' object has no attribute 'canvas'[/+]tacaswell commentedon Aug 17, 2022
Can you reproduce this without pandas?
jklymak commentedon Aug 17, 2022
Even with pandas I cannot reproduce this locally. But a few things did change with the backend fallbacks, so its not impossible the CI is not falling back gracefully?
tacaswell commentedon Aug 17, 2022
new_figure_managershould never returnNoneso something very fishy is going on.@1kastner can you get the package lists from the last working and first broken run?
1kastner commentedon Aug 17, 2022
My last working build on readthedocs used the following packages installed via pip:
First, the default packages of readthedocs:
...and then the packages I need to build the docs:
That was one day and two hours ago. The first build afterwards happend 7 hours ago and failed with these versions:
...and in the second step
In both cases, Python 3.10.4 was used and when we compare the output, also the matplotlib version was obviously the same. However, there was an update from
matplotlib-inline-0.1.3tomatplotlib-inline-0.1.5. Is that a possible source?I know that the project comes with some complexity and that there are a few libraries around that most likely have nothing to do with this error. I will try to work on a minimal example if nothing jumps to our minds here.
I checked the commit between the last successful and first failing build. It only contains some changes in the unittests, no change in dependencies. As both the CI on GitHub and readthedocs are failing, it is rather unlikely that this bug is due to a miraculous specific change on their server side.
1kastner commentedon Aug 17, 2022
...and tada, at https://github.com/ipython/matplotlib-inline/blob/master/matplotlib_inline/backend_inline.py#L55 we have a return statement that potentially makes the figure manager
None. That code changes 3 months ago and released yesterday, see https://pypi.org/project/matplotlib-inline/#history.tacaswell commentedon Aug 17, 2022
For now pinning that back will get your tests running again, but someone needs to sort out what the right fix here is.
I was a bit through because you reported using the agg backend in the original post.
I am 95% sure that we need to fix this on the matplotib-inline side.
tacaswell commentedon Aug 17, 2022
Thank you for tracking this down @1kastner !
1kastner commentedon Aug 17, 2022
@tacaswell I did not understand matplotlib well enough to tell you that the other backend was effectively used. I am sorry for the confusion I introduced!
tacaswell commentedon Aug 17, 2022
In general adding
print(mpl.get_backend())right above the offending code will give the right answer.jklymak commentedon Aug 17, 2022
We can close this from our end, right?
tacaswell commentedon Aug 17, 2022
I am only 95% sure it is a bug on their side. It is possible than returning
Nonethere used to work and merely opted out of pylab's tracking (rather than never supporting None here and this was a bug introduced in the recent refactor over there).1kastner commentedon Aug 17, 2022
I have created a new ticket at their repository and fixed the version in my project for the meantime. With the previous version set, everything works again. I will keep you updated. For me, both options (closing the ticket or waiting for the final answer before doing that) are okay.
1kastner commentedon Aug 17, 2022
And of course thank you very much for the very fast support!
jklymak commentedon Aug 17, 2022
Well lets close here and re-open if ipython/matplotlib-inline#18 bounces back to us. Stuff never gets closed otherwise....
1kastner commentedon Aug 18, 2022
The error was spotted and a new release drafted. Generally speaking, a more detailled error message that also included the currently used backend would have been awesome and it would have saved me from coming here in the first place. But I also see that this is not easy to achieve as matplotlib and its respective backend are deeply integrated.