Issue with tight_layout with matplotlib and cartopy - python

I recently switched to Matplotlib 3.3.1 and my old script start to complain. I guess it is an issue with cartopy. Here is a minimum reproducible example
import cartopy.crs as ccrs
fig, ax = plt.subplots(2, 2,
subplot_kw=dict(projection=ccrs.PlateCarree()),
figsize=[12,7], sharex=True, sharey=True)
plt.tight_layout()
Any suggestion to fix this issue?
Here I copy the error message:
Traceback (most recent call last):
File "", line 4, in
plt.tight_layout()
File
"C:\Users\Vinod\anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py",
line 451, in wrapper
return func(*args, **kwargs)
File
"C:\Users\Vinod\anaconda3\lib\site-packages\matplotlib\pyplot.py",
line 1490, in tight_layout
gcf().tight_layout(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
File
"C:\Users\Vinod\anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py",
line 411, in wrapper
return func(*inner_args, **inner_kwargs)
File
"C:\Users\Vinod\anaconda3\lib\site-packages\matplotlib\figure.py",
line 2613, in tight_layout
kwargs = get_tight_layout_figure(
File
"C:\Users\Vinod\anaconda3\lib\site-packages\matplotlib\tight_layout.py",
line 303, in get_tight_layout_figure
kwargs = auto_adjust_subplotpars(fig, renderer,
File
"C:\Users\Vinod\anaconda3\lib\site-packages\matplotlib\tight_layout.py",
line 84, in auto_adjust_subplotpars
bb += [ax.get_tightbbox(renderer, for_layout_only=True)]
File
"C:\Users\Vinod\anaconda3\lib\site-packages\matplotlib\axes_base.py",
line 4203, in get_tightbbox
bbox = a.get_tightbbox(renderer)
File
"C:\Users\Vinod\anaconda3\lib\site-packages\matplotlib\artist.py",
line 278, in get_tightbbox
bbox = self.get_window_extent(renderer)
File
"C:\Users\Vinod\anaconda3\lib\site-packages\matplotlib\patches.py",
line 598, in get_window_extent
return self.get_path().get_extents(self.get_transform())
File
"C:\Users\Vinod\anaconda3\lib\site-packages\matplotlib\path.py", line
603, in get_extents
return Bbox([xys.min(axis=0), xys.max(axis=0)])
File
"C:\Users\Vinod\anaconda3\lib\site-packages\numpy\core_methods.py",
line 43, in _amin
return umr_minimum(a, axis, None, out, keepdims, initial, where)
ValueError: zero-size array to reduction operation minimum which has
no identity

This was a known issue and was addressed in: https://github.com/SciTools/cartopy/issues/1207. (Making sure you have the latest version of cartopy may resolve this issue).
In the meanwhile, as a workaround it was noted that you could make a call to fig.canvas.draw() before your call to plt.tight_layout().

Related

Exception thrown in PyCharm debug mode but not in run mode (seaborn, matplotlib)

I'm using
PyCharm 2021.2.3 Community Edition
Python interpreter 3.10.0
matplotlib 3.5.0
seaborn 0.11.2
numpy 1.21.4
pandas 1.3.4
PySimpleGUI 4.55.1
When I run the following script, it is fine in run mode but in debug mode it throws an exception. Here's the script:
import numpy as np
import pandas as pd
import PySimpleGUI as sg
import seaborn as sns
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
def init_data():
r1 = np.random.rand(5, 4)
columns = [f"var{i}" for i in range(1, 5)]
df = pd.DataFrame(r1, columns=columns)
df.insert(0, 'year', range(2021, 2026))
df.insert(1, 'scenario', 'test1')
ldf = pd.melt(df, id_vars=['year', 'scenario'], value_vars=columns, var_name='percentile', value_name='carbon')
return ldf
def draw_figure(canvas, figure):
figure_canvas_agg = FigureCanvasTkAgg(figure, canvas)
figure_canvas_agg.draw()
figure_canvas_agg.get_tk_widget().pack(side='top', fill='both', expand=1)
return figure_canvas_agg
# define the window layout
layout = [[sg.Text('Plot test')],
[sg.Canvas(key='-CANVAS-')],
[sg.Button('Ok')]]
# create the form and show it without the plot
window = sg.Window('Testing seaborn in PySimpleGUI', layout, finalize=True,
element_justification='center', font='Helvetica 18')
figure = Figure()
ax = figure.subplots()
sns.lineplot(x='year', y='carbon', hue='percentile', data=init_data(), ax=ax)
# add the plot to the window
fig_canvas_agg = draw_figure(window['-CANVAS-'].TKCanvas, figure)
event, values = window.read()
window.close()
And here's the stacktrace:
Traceback (most recent call last):
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\core\getlimits.py", line 384, in __new__
dtype = numeric.dtype(dtype)
TypeError: 'NoneType' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.2.3\plugins\python-ce\helpers\pydev\pydevd.py", line 1483, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.2.3\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "D:/OneDrive/OneDrive - Louise Pryor & Co Ltd/Actuarial/Carbon/Carbon/seaborntest.py", line 39, in <module>
sns.lineplot(x='year', y='carbon', hue='percentile', data=init_data(), ax=ax)
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\seaborn\_decorators.py", line 46, in inner_f
return f(**kwargs)
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\seaborn\relational.py", line 710, in lineplot
p.plot(ax, kwargs)
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\seaborn\relational.py", line 557, in plot
self._add_axis_labels(ax)
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\seaborn\_core.py", line 1194, in _add_axis_labels
x_visible = any(t.get_visible() for t in ax.get_xticklabels())
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axes\_base.py", line 75, in wrapper
return get_method(self)(*args, **kwargs)
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axis.py", line 1249, in get_ticklabels
return self.get_majorticklabels()
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axis.py", line 1201, in get_majorticklabels
ticks = self.get_major_ticks()
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axis.py", line 1371, in get_major_ticks
numticks = len(self.get_majorticklocs())
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axis.py", line 1277, in get_majorticklocs
return self.major.locator()
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\ticker.py", line 2113, in __call__
vmin, vmax = self.axis.get_view_interval()
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axis.py", line 1987, in getter
return getattr(getattr(self.axes, lim_name), attr_name)
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axes\_base.py", line 781, in viewLim
self._unstale_viewLim()
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axes\_base.py", line 776, in _unstale_viewLim
self.autoscale_view(**{f"scale{name}": scale
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axes\_base.py", line 2932, in autoscale_view
handle_single_axis(
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axes\_base.py", line 2895, in handle_single_axis
x0, x1 = locator.nonsingular(x0, x1)
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\ticker.py", line 1654, in nonsingular
return mtransforms.nonsingular(v0, v1, expander=.05)
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\transforms.py", line 2880, in nonsingular
if maxabsvalue < (1e6 / tiny) * np.finfo(float).tiny:
File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\core\getlimits.py", line 387, in __new__
dtype = numeric.dtype(type(dtype))
TypeError: 'NoneType' object is not callable
Has anyone seen this before or have any ideas?
I had the same issue until I changed my version of python from 3.10 to 3.9.5.
This did the ugly trick for debugging under pyCharm 2022.1.1, python 3.10.4, scipy=1.8.0
numpy=1.22.3
pandas=1.4.1
AK lame handling of debugg issue with numpy vs pandas/scipy np.core.numeric.dtype
if sys.gettrace():
np.core.numeric.dtype = np.dtype

Adding PolyCOllection of Violinplot into add_collection3d

I am trying to modify the plot shown in this answer, but replacing the fill_between with violin plots at each tick.
A naive implementation made me try following,
import matplotlib.pylab as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
x = np.linspace(1,5,100)
y1 = np.ones(x.size)
y2 = np.ones(x.size)*2
y3 = np.ones(x.size)*3
z = np.sin(x/2)
plt.figure()
ax = plt.subplot(projection='3d')
ax.plot(x, y1, z, color='r')
ax.plot(x, y2, z, color='g')
ax.plot(x, y3, z, color='b')
handle = plt.violinplot(x)
ax.add_collection3d(handle, zs=1, zdir='y')
The error that pops up is: AttributeError: 'PolyCollection' object has no attribute 'do_3d_projection'.
The error origin can be traced by the following log:
runcell(7, 'Figure.py')
Traceback (most recent call last):
File "Figure.py", line 163, in <module>
ax.add_collection3d(handle, zs=1, zdir='y')
File "C:\Users\sarth\.conda\envs\master\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 2252, in add_collection3d
super().add_collection(col)
File "C:\Users\sarth\.conda\envs\master\lib\site-packages\matplotlib\axes\_base.py", line 1921, in add_collection
label = collection.get_label()
AttributeError: 'dict' object has no attribute 'get_label'
Traceback (most recent call last):
File "C:\Users\sarth\AppData\Roaming\Python\Python36\site-packages\IPython\core\formatters.py", line 341, in __call__
return printer(obj)
File "C:\Users\sarth\AppData\Roaming\Python\Python36\site-packages\IPython\core\pylabtools.py", line 248, in <lambda>
png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
File "C:\Users\sarth\AppData\Roaming\Python\Python36\site-packages\IPython\core\pylabtools.py", line 132, in print_figure
fig.canvas.print_figure(bytes_io, **kw)
File "C:\Users\sarth\.conda\envs\master\lib\site-packages\matplotlib\backend_bases.py", line 2193, in print_figure
self.figure.draw(renderer)
File "C:\Users\sarth\.conda\envs\master\lib\site-packages\matplotlib\artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\sarth\.conda\envs\master\lib\site-packages\matplotlib\figure.py", line 1864, in draw
renderer, self, artists, self.suppressComposite)
File "C:\Users\sarth\.conda\envs\master\lib\site-packages\matplotlib\image.py", line 131, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\sarth\.conda\envs\master\lib\site-packages\matplotlib\artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\sarth\.conda\envs\master\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 447, in draw
reverse=True)):
File "C:\Users\sarth\.conda\envs\master\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 446, in <lambda>
key=lambda col: col.do_3d_projection(renderer),
AttributeError: 'PolyCollection' object has no attribute 'do_3d_projection'
<Figure size 432x288 with 1 Axes>
Also tried using individual body objects using plt.violinplot(x)['objects'][i] but the same error is returned.

Bokeh histogram will not plot

My issue seems exactly like this post (albeit column types may be different):
Cannot plot Histogram on Ubuntu 14.04
The code is straight out of the docs http://docs.bokeh.org/en/0.10.0/docs/user_guide/charts.html#histograms
I couldn't comment on that post so needed to ask again if a solution was found...
My system is SUSE. Just trying to plot a simple histogram of datetimes from a pandas df series.
>>>df
ACQ_DATE
0 2017-01-28
1 2017-01-28
... ...
456365 2017-07-25
456366 2017-07-25
>>>hist = Histogram(df['ACQ_DATE'], title="Fire Frequency")
2017-08-22 11:56:15,240 Error running application handler <bokeh.application.handlers.script.ScriptHandler object at 0x2b6cc2c8f358>: expected an element of either Column(Float) or Column(String), got array(['2017- 01-28T00:00:00.000000000', '2017-01-28T00:00:00.000000000',
'2017-01-28T00:00:00.000000000', ...,
'2017-07-25T00:00:00.000000000', '2017-07-25T00:00:00.000000000',
'2017-07-25T00:00:00.000000000'], dtype='datetime64[ns]')
File "properties.py", line 676, in validate:
raise ValueError("expected an element of either %s, got %r" % (nice_join (self.type_params), value)) Traceback (most recent call last):
File "/home/byed/venv36/lib/python3.6/site- packages/bokeh/application/handlers/code_runner.py", line 81, in run
exec(self._code, module.__dict__)
File "/home/byed/job/fire/report_fire_points.py", line 118, in <module>
hist = Histogram(df['ACQ_DATE'], title="Fire Frequency") #, tools='pan,wheel_zoom,box_select,reset')
File "/home/byed/venv36/lib/python3.6/site- packages/bkcharts/builders/histogram_builder.py", line 107, in Histogram
return create_and_build(HistogramBuilder, data, **kw)
File "/home/byed/venv36/lib/python3.6/site-packages/bkcharts/builder.py", line 56, in create_and_build
chart.add_builder(builder)
File "/home/byed/venv36/lib/python3.6/site-packages/bkcharts/chart.py", line 155, in add_builder
builder.create(self)
File "/home/byed/venv36/lib/python3.6/site-packages/bkcharts/builder.py", line 512, in create
chart.add_renderers(self, renderers)
File "/home/byed/venv36/lib/python3.6/site-packages/bkcharts/chart.py", line 150, in add_renderers
self.renderers += renderers
File "/home/byed/venv36/lib/python3.6/site-packages/bokeh/core/property/containers.py", line 76, in wrapper
result = func(self, *args, **kwargs)
File "/home/byed/venv36/lib/python3.6/site- packages/bokeh/core/property/containers.py", line 172, in __iadd__
return super(PropertyValueList, self).__iadd__(y)
File "/home/byed/venv36/lib/python3.6/site- packages/bkcharts/builders/bar_builder.py", line 221, in yield_renderers
**group_kwargs)
File "/home/byed/venv36/lib/python3.6/site-packages/bkcharts/glyphs.py", line 950, in __init__
super(HistogramGlyph, self).__init__(**kwargs)
File "/home/byed/venv36/lib/python3.6/site-packages/bkcharts/glyphs.py", line 490, in __init__
super(AggregateGlyph, self).__init__(**kwargs)
File "/home/byed/venv36/lib/python3.6/site-packages/bkcharts/models.py", line 83, in __init__
super(CompositeGlyph, self).__init__(**properties)
File "/home/byed/venv36/lib/python3.6/site-packages/bokeh/core/has_props.py", line 246, in __init__
setattr(self, name, value)
File "/home/byed/venv36/lib/python3.6/site- packages/bokeh/core/has_props.py", line 274, in __setattr__
super(HasProps, self).__setattr__(name, value)
File "/home/byed/venv36/lib/python3.6/site- packages/bokeh/core/property/descriptors.py", line 495, in __set__
self._internal_set(obj, value, setter)
File "/home/byed/venv36/lib/python3.6/site-packages/bokeh/core/property/descriptors.py", line 713, in _internal_set
value = self.property.prepare_value(obj, self.name, value)
File "/home/byed/venv36/lib/python3.6/site-packages/bokeh/core/property/bases.py", line 290, in prepare_value
raise e
File "/home/byed/venv36/lib/python3.6/site-packages/bokeh/core/property/bases.py", line 283, in prepare_value
self.validate(value)
File "/home/byed/venv36/lib/python3.6/site-packages/bokeh/core/properties.py", line 676, in validate
raise ValueError("expected an element of either %s, got %r" % (nice_join (self.type_params), value))
ValueError: expected an element of either Column(Float) or Column(String), got array(['2017-01-28T00:00:00.000000000', '2017-01-28T00:00:00.000000000',
'2017-01-28T00:00:00.000000000', ...,
'2017-07-25T00:00:00.000000000', '2017-07-25T00:00:00.000000000',
'2017-07-25T00:00:00.000000000'], dtype='datetime64[ns]')
Any help would be much appreciated.
Cheers n Thanks
Don't use bokeh.charts (now a separate bkcharts project), including Histogram. The bkcharts project is currently abandoned and unmaintained. However, it's pretty trivial to create histograms using bokeh.plotting which is the stable and well-supported core API of Bokeh:
import numpy as np
from bokeh.io import show, output_file
from bokeh.plotting import figure
data = np.random.normal(0, 0.5, 1000)
hist, edges = np.histogram(data, density=True, bins=50)
p = figure()
p.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], line_color="white")
output_file("hist.html")
show(p)
Alternatively, if you want a very-high level statistical charting API on top of Bokeh, then check out these options:
Holoviews
PandasBokeh
Chartify
Thanks to #bigreddot!
I'm using Google Colab as an online Jupyter notebook environment. And to plot Bokeh histogram in Colab, I had to tweak the sample code snippet above by using output_notebook():
import numpy as np
from bokeh.io import show, output_notebook
from bokeh.plotting import figure
output_notebook()
data = np.random.normal(0, 0.5, 1000)
hist, edges = np.histogram(data, density=True, bins=10)
p = figure()
p.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], line_color="white")
show(p)

python: AttributeError: 'ZAxis' object has no attribute '_set_scale'

I recently updated to OS X Maverics and as one of the results it broke my python matplotlib 3D plotting. For example when I run this:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
I get:
Traceback (most recent call last):
File "/Users/nacho/Documents/Proyecto/codigo/RLS/run_rls.py", line 89, in <module>
n_plot([bunch.ff_weighted_estimation_error for bunch in rls.rls_bunchs], 'Peso')
File "/Users/nacho/Documents/Proyecto/codigo/RLS/run_rls.py", line 43, in n_plot
ax = fig.gca(projection='3d')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/figure.py", line 1066, in gca
return self.add_subplot(111, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/figure.py", line 789, in add_subplot
a = subplot_class_factory(projection_class)(self, *args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py", line 8457, in __init__
self._axes_class.__init__(self, fig, self.figbox, **kwargs)
File "/Library/Python/2.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 91, in __init__
*args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py", line 463, in __init__
self.cla()
File "/Library/Python/2.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 1040, in cla
self.zaxis._set_scale('linear')
AttributeError: 'ZAxis' object has no attribute '_set_scale'
I'm running Python 2.7.5, and matplotlib 1.3.1.

How to get rid of maximum recursion depth error while plotting interactively?

I'm trying to build an interactive plot. This one is supposed to clear the figure if clicked within axes and draw a circle at a random place. The code is as follows:
import matplotlib.pyplot as plt
import random
def draw_circle(event):
if event.inaxes:
print(event.xdata, event.ydata)
plt.cla()
a = random.randint(0,100)
b = random.randint(0,100)
s, = plt.plot(a,b,'o', ms=100, color="blue",visible=True )
plt.show()
fig = plt.figure()
ax = plt.subplot(111)
s, = plt.plot(1,2,'o', ms=100, color="blue",visible=True )
plt.connect("button_press_event", draw_circle)
plt.show()
After clicking for 42 times, the program breaks and I get the following traceback:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1413, in __call__
return self.func(*args)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 286, in button_press_event
FigureCanvasBase.button_press_event(self, x, y, num, guiEvent=event)
File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 1632, in button_press_event
self.callbacks.process(s, mouseevent)
File "/usr/lib/pymodules/python2.7/matplotlib/cbook.py", line 262, in process
proxy(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/cbook.py", line 192, in __call__
return mtd(*args, **kwargs)
File "/home/almarahat/Dropbox/python/GUI/Testing site/test_rt/baud_test.py", line 8, in draw_circle
plt.cla()
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2784, in cla
ret = gca().cla()
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 842, in cla
spine.cla()
File "/usr/lib/pymodules/python2.7/matplotlib/spines.py", line 157, in cla
self.axis.cla()
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 731, in cla
self.reset_ticks()
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 744, in reset_ticks
self.majorTicks.extend([self._get_tick(major=True)])
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 1553, in _get_tick
return XTick(self.axes, 0, '', major=major, **tick_kw)
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 141, in __init__
self.tick2line = self._get_tick2line()
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 401, in _get_tick2line
l.set_transform(self.axes.get_xaxis_transform(which='tick2'))
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 586, in get_xaxis_transform
return self.spines['top'].get_spine_transform()
File "/usr/lib/pymodules/python2.7/matplotlib/spines.py", line 374, in get_spine_transform
self._ensure_position_is_set()
File "/usr/lib/pymodules/python2.7/matplotlib/spines.py", line 140, in _ensure_position_is_set
self.set_position(self._position)
File "/usr/lib/pymodules/python2.7/matplotlib/spines.py", line 365, in set_position
self.axis.cla()
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 731, in cla
self.reset_ticks()
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 744, in reset_ticks
self.majorTicks.extend([self._get_tick(major=True)])
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 1553, in _get_tick
return XTick(self.axes, 0, '', major=major, **tick_kw)
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 140, in __init__
self.tick1line = self._get_tick1line()
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 383, in _get_tick1line
zorder=self._zorder,
File "/usr/lib/pymodules/python2.7/matplotlib/lines.py", line 195, in __init__
self._marker = MarkerStyle()
File "/usr/lib/pymodules/python2.7/matplotlib/markers.py", line 112, in __init__
self.set_marker(marker)
File "/usr/lib/pymodules/python2.7/matplotlib/markers.py", line 171, in set_marker
self._recache()
File "/usr/lib/pymodules/python2.7/matplotlib/markers.py", line 116, in _recache
self._path = Path(np.empty((0,2)))
File "/usr/lib/pymodules/python2.7/matplotlib/path.py", line 112, in __init__
if ma.isMaskedArray(vertices):
File "/usr/local/lib/python2.7/dist-packages/numpy-1.6.2-py2.7-linux-x86_64.egg/numpy/ma/core.py", line 5683, in isMaskedArray
return isinstance(x, MaskedArray)
RuntimeError: maximum recursion depth exceeded while calling a Python object
At this point, I am not certain where the recursion occurs and how to alleviate this error.
I understand (from other Q&As) that I could enhance my stack limit and get around the problem. However, I don't consider that as a solution in this particular case and would like to get to the bottom of this.
Any help would be appreciate.
Thanks in advance.
Additional Information:
The main functionality that matters include clearing the figure and drawing something new on clicking the canvas.
The clicking does not raise this error, if I am not trying to plot something. Thus, I suspect, I'm missing something in handling matplotlib.
Instead of plt.show(), from within your callback call plt.draw(). The problem is that plt.show runs a mainloop of the GUI library; you just want to update what is shown within the existing mainloop. Using the Qt backend, your code would show the error QCoreApplication::exec: The event loop is already running.
See What is interactive mode? for more guidance on how to use Matplotlib interactively.

Categories