Related
I have created a python program that uses matplotlib to plot data and it had been working fine until today, an error occured. The program uses AutoDateLocator and ConciseDateFormatter. As you can see in the last line of the error log below, the received error is:
> IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
Since it would be really difficult to post more details about my program functionality as well as the data used, I was wondering if there is an obvious solution to the above-mentioned problem, or if you could guide me to where I should look for the problem.
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\tkinter_init_.py", line 1883,
in call
return self.func(*args)
File "C:\Users\Nick\Desktop\Uni\TUC
studies\thesis\Code\python\test\myGUI_V3.py", line 841, in plotMeas
fig.tight_layout()
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py",
line 411, in
wrapper
return func(*inner_args, **inner_kwargs)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\figure.py",
line 2613, in tight_layout
kwargs = get_tight_layout_figure(
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\tight_layout.py",
line 303, in get_tight_layout_figure
kwargs = auto_adjust_subplotpars(fig, renderer,
File
"C:\ProgramData\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:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes_base.py",
line 4155, in
get_tightbbox
bb_xaxis = self.xaxis.get_tightbbox(
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axis.py", line
1109, in get_tightbbox
ticks_to_draw = self._update_ticks()
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axis.py", line
1030, in _update_ticks
minor_labels = self.minor.formatter.format_ticks(minor_locs)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\dates.py", line
797, in format_ticks
if len(np.unique(tickdate[:, level])) > 1:
IndexError: too many indices for array: array is 1-dimensional, but 2
were indexed
Traceback (most recent call last):
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt5.py",
line 480, in
_draw_idle
self.draw()
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py",
line 407, in draw
self.figure.draw(self.renderer)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\artist.py",
line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\figure.py",
line 1863, in draw
mimage._draw_list_compositing_images(
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\image.py", line
131, in
_draw_list_compositing_images
a.draw(renderer)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\artist.py",
line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py",
line 411, in wrapper
return func(*inner_args, **inner_kwargs)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes_base.py",
line 2747, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\image.py", line
131, in
_draw_list_compositing_images
a.draw(renderer)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\artist.py",
line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axis.py", line
1164, in draw
ticks_to_draw = self._update_ticks()
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axis.py", line
1030, in _update_ticks
minor_labels = self.minor.formatter.format_ticks(minor_locs)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\dates.py", line
797, in format_ticks
if len(np.unique(tickdate[:, level])) > 1:
IndexError: too many indices for array: array is 1-dimensional, but 2
were indexed
Traceback (most recent call last):
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt5.py",
line 480, in
_draw_idle
self.draw()
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py",
line 407, in draw
self.figure.draw(self.renderer)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\artist.py",
line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\figure.py",
line 1863, in draw
mimage._draw_list_compositing_images(
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\image.py", line
131, in
_draw_list_compositing_images
a.draw(renderer)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\artist.py",
line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py",
line 411, in wrapper
return func(*inner_args, **inner_kwargs)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes_base.py",
line 2747, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\image.py", line
131, in
_draw_list_compositing_images
a.draw(renderer)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\artist.py",
line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axis.py", line
1164, in draw
ticks_to_draw = self._update_ticks()
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axis.py", line
1030, in _update_ticks
minor_labels = self.minor.formatter.format_ticks(minor_locs)
File
"C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\dates.py", line
797, in format_ticks
if len(np.unique(tickdate[:, level])) > 1:
IndexError: too many indices for array: array is 1-dimensional, but 2
were indexed
As it turns out, it was a problem of the setup of the AutoDateLocator. Because of the specific dataset, the minor ticks could not be set correctly, based on the values I had selected for minticks, maxticks, and for the intervald tuples chosen. As a result, when the ConciseDateFormatter tried to use the locator for the minor ticks, the above-mentioned error occured.
When used a simple DateFormatter, there was no error, but neither the minor ticks, nor their labels appeared on the plot.
I'm making a realtime audio visualizer in python with pyaudio and using matplotlib to plot a graph. When the code reaches the line shown in the code it gives a Value Error: shape mismatch: objects cannot be broadcast to a single shape. and also says there was an Exception in Tkinter callback. I've tried looking everywhere but I couldn't find anything about this. Also when I remove the line that is causing that error, the code works just fine. Any idea how this can be fixed?
Code:
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16,
channels=channelcount,
rate=int(device_info["defaultSampleRate"]),
input=True,
frames_per_buffer=defaultframes,
input_device_index=device_info["index"],
as_loopback=True)
fig, (ax, ax2) = plt.subplots(2, figsize=(15, 8))
x = np.arange(0, 2 * CHUNK, 2)
x_fft = np.linspace(0, device_info["defaultSampleRate"], CHUNK)
line, = ax.plot(x, np.random.rand(CHUNK), '-', lw=2)
line_fft, = ax2.semilogx(x_fft, np.random.rand(CHUNK), '-', lw=2)
offset = 2000
ax.set_ylim(0, offset)
ax.set_xlim(0, 2 * CHUNK)
plt.setp(ax, xticks=[0, CHUNK, 2 * CHUNK], yticks=[0, 128, 255])
ax2.set_xlim(20, device_info["defaultSampleRate"] / 2)
ax2.set_ylim(0, 20)
fig.show()
while True:
data = stream.read(CHUNK)
data_int = struct.unpack(str(2 * CHUNK) + 'h', data)
line.set_ydata(np.array(data_int)) <------------------------------- ERROR HAPPENS HERE
y_fft = fft(data_int)
line_fft.set_ydata(np.abs(y_fft[0:CHUNK]) * 2 / (256 * CHUNK))
fig.canvas.draw()
fig.canvas.flush_events()
Error:
Traceback (most recent call last):
File "E:\Python\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\backends\_backend_tk.py", line 259, in resize
self.draw()
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 9, in draw
super(FigureCanvasTkAgg, self).draw()
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\backends\backend_agg.py", line 393, in draw
self.figure.draw(self.renderer)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\figure.py", line 1736, in draw
renderer, self, artists, self.suppressComposite)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\image.py", line 137, in _draw_list_compositing_images
a.draw(renderer)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\axes\_base.py", line 2630, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\image.py", line 137, in _draw_list_compositing_images
a.draw(renderer)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\lines.py", line 759, in draw
self.recache()
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\lines.py", line 679, in recache
self._xy = np.column_stack(np.broadcast_arrays(x, y)).astype(float)
File "<__array_function__ internals>", line 6, in broadcast_arrays
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\numpy\lib\stride_tricks.py", line 264, in broadcast_arrays
shape = _broadcast_shape(*args)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\numpy\lib\stride_tricks.py", line 191, in _broadcast_shape
b = np.broadcast(*args[:32])
ValueError: shape mismatch: objects cannot be broadcast to a single shape
Exception in Tkinter callback
Traceback (most recent call last):
File "E:\Python\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "E:\Python\lib\tkinter\__init__.py", line 749, in callit
func(*args)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\backends\_backend_tk.py", line 270, in idle_draw
self.draw()
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 9, in draw
super(FigureCanvasTkAgg, self).draw()
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\backends\backend_agg.py", line 393, in draw
self.figure.draw(self.renderer)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\figure.py", line 1736, in draw
renderer, self, artists, self.suppressComposite)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\image.py", line 137, in _draw_list_compositing_images
a.draw(renderer)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\axes\_base.py", line 2630, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\image.py", line 137, in _draw_list_compositing_images
a.draw(renderer)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\lines.py", line 759, in draw
self.recache()
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\lines.py", line 679, in recache
self._xy = np.column_stack(np.broadcast_arrays(x, y)).astype(float)
File "<__array_function__ internals>", line 6, in broadcast_arrays
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\numpy\lib\stride_tricks.py", line 264, in broadcast_arrays
shape = _broadcast_shape(*args)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\numpy\lib\stride_tricks.py", line 191, in _broadcast_shape
b = np.broadcast(*args[:32])
ValueError: shape mismatch: objects cannot be broadcast to a single shape
Traceback (most recent call last):
File "E:/PycharmProjects/LedProject/test3.py", line 112, in <module>
fig.canvas.draw()
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 9, in draw
super(FigureCanvasTkAgg, self).draw()
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\backends\backend_agg.py", line 393, in draw
self.figure.draw(self.renderer)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\figure.py", line 1736, in draw
renderer, self, artists, self.suppressComposite)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\image.py", line 137, in _draw_list_compositing_images
a.draw(renderer)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\axes\_base.py", line 2630, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\image.py", line 137, in _draw_list_compositing_images
a.draw(renderer)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\lines.py", line 759, in draw
self.recache()
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\matplotlib\lines.py", line 679, in recache
self._xy = np.column_stack(np.broadcast_arrays(x, y)).astype(float)
File "<__array_function__ internals>", line 6, in broadcast_arrays
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\numpy\lib\stride_tricks.py", line 264, in broadcast_arrays
shape = _broadcast_shape(*args)
File "E:\PycharmProjects\LedProject\venv\lib\site-packages\numpy\lib\stride_tricks.py", line 191, in _broadcast_shape
b = np.broadcast(*args[:32])
ValueError: shape mismatch: objects cannot be broadcast to a single shape```
I've been trying to use the Figure.figure.plot() function from matplotlib
figplot = fig.add_subplot(111)
print(lines[2].get_xdata()[0])
print(lines[2].get_ydata()[0])
figplot.plot(lines[2].get_xdata()[0], lines[2].get_ydata()[0], c='ro')
but upon trying to execute this, I'm getting the following error message:
Traceback (most recent call last):
File "/usr/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/backends/_backend_tk.py", line 259, in resize
self.draw()
File "/usr/local/lib/python3.7/dist-packages/matplotlib/backends/backend_tkagg.py", line 9, in draw
super(FigureCanvasTkAgg, self).draw()
File "/usr/local/lib/python3.7/dist-packages/matplotlib/backends/backend_agg.py", line 388, in draw
self.figure.draw(self.renderer)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/figure.py", line 1709, in draw
renderer, self, artists, self.suppressComposite)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/image.py", line 135, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/axes/_base.py", line 2647, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/image.py", line 135, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/lines.py", line 783, in draw
lc_rgba = mcolors.to_rgba(self._color, self._alpha)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/colors.py", line 177, in to_rgba
rgba = _to_rgba_no_colorcycle(c, alpha)
File "/usr/local/lib/python3.7/dist-packages/matplotlib/colors.py", line 233, in _to_rgba_no_colorcycle
raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
ValueError: Invalid RGBA argument: 'ro'
I've noticed that for scatter plots, the colors have to be an array, but this isn't a scatter plot.
the values of lines[2].get_xdata()[0] and lines[2].get_ydata()[0] is as follows:
0.5766199490353112
1648.0609161647387
Is there any way to find out what's going wrong? I'm using tkinter along with matplotlib
ro is color-marker code. You should remove c=:
figplot.plot(lines[2].get_xdata()[0], lines[2].get_ydata()[0], 'ro')
Or maybe specify color without the marker o:
figplot.plot(lines[2].get_xdata()[0], lines[2].get_ydata()[0], c='r')
I am plotting a barplot using the seaborn.barplot method. The plotting is going through fine. When I am trying to add text on above the bars for better explanation using text method I am running into above mentioned issue.
Below is the code I have tried. With this code I am getting plot like this but i need plot like
this
where values displayed at top of bar are the raised_amount_in_millions value
Here is my code
groupedvalues=master_frame_backup1.groupby('funding_round_type')['raised_amount_in_millions'].mean().reset_index()
#groupedvalues
plt.figure(figsize=(30,8))
pal = sns.color_palette("Greens_d", len(groupedvalues))
rank = groupedvalues["raised_amount_in_millions"].argsort().argsort()
g=sns.barplot(x='funding_round_type',y='raised_amount_in_millions',data=groupedvalues, palette=np.array(pal[::-1])[rank])
for index, row in groupedvalues.iterrows():
g.text(row.funding_round_type, row.raised_amount_in_millions," "+str(row.raised_amount_in_millions), color='black', ha="center")
plt.show()
But I am running into above mentioned error. Any help?
Here is the error stack
Here is the error stack
Error in callback .post_execute at 0x00000211F5EB2378> (for post_execute):
Traceback (most recent call last):
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\pyplot.py", line 109, in post_execute
draw_all()
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib_pylab_helpers.py", line 132, in draw_all
f_mgr.canvas.draw_idle()
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\backend_bases.py", line 1899, in draw_idle
self.draw(*args, **kwargs)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 402, in draw
self.figure.draw(self.renderer)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\artist.py", line 50, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\figure.py", line 1649, in draw
renderer, self, artists, self.suppressComposite)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\image.py", line 138, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\artist.py", line 50, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes_base.py", line 2610, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\image.py", line 138, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\artist.py", line 50, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\text.py", line 709, in draw
bbox, info, descent = textobj._get_layout(renderer)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\text.py", line 286, in _get_layout
key = self.get_prop_tup(renderer=renderer)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\text.py", line 871, in get_prop_tup
x, y = self.get_unitless_position()
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\text.py", line 853, in get_unitless_position
x = float(self.convert_xunits(self._x))
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\artist.py", line 186, in convert_xunits
return ax.xaxis.convert_units(x)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axis.py", line 1530, in convert_units
ret = self.converter.convert(x, self.units, self)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py", line 53, in convert
unit.update(values)
AttributeError: 'NoneType' object has no attribute 'update'
Traceback (most recent call last):
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\core\formatters.py", line 341, in call
return printer(obj)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\core\pylabtools.py", line 244, in
png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\core\pylabtools.py", line 128, in print_figure
fig.canvas.print_figure(bytes_io, **kw)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\backend_bases.py", line 2049, in print_figure
**kwargs)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 510, in print_png
FigureCanvasAgg.draw(self)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 402, in draw
self.figure.draw(self.renderer)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\artist.py", line 50, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\figure.py", line 1649, in draw
renderer, self, artists, self.suppressComposite)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\image.py", line 138, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\artist.py", line 50, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes_base.py", line 2610, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\image.py", line 138, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\artist.py", line 50, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\text.py", line 709, in draw
bbox, info, descent = textobj._get_layout(renderer)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\text.py", line 286, in _get_layout
key = self.get_prop_tup(renderer=renderer)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\text.py", line 871, in get_prop_tup
x, y = self.get_unitless_position()
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\text.py", line 853, in get_unitless_position
x = float(self.convert_xunits(self._x))
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\artist.py", line 186, in convert_xunits
return ax.xaxis.convert_units(x)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axis.py", line 1530, in convert_units
ret = self.converter.convert(x, self.units, self)
File "C:\Users\mmajgaon.ORADEV\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\category.py", line 53, in convert
unit.update(values)
AttributeError: 'NoneType' object has no attribute 'update'
I try to run the following python code (Python 3.4.7 + scipy installed; MikTeX 2.9.4476 installed; Windows 7)
from matplotlib import pyplot as plt
from matplotlib.pyplot import rc
rc('text', usetex=True)
# plotting
data = range(100)
plt.plot(data, data, label='0.3 m')
plt.legend()
plt.savefig("test.png")
plt.savefig("test.svg")
# plt.show()
and get the following errors if I use plt.savefig("test.svg") or any other vector graphics format. Without this saving command everything works fine. Printed Errors:
Traceback (most recent call last):
File "U:\ICCAP\S_SVN\ETHAN\test.py", line 12, in <module>
plt.savefig("test.svg")
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\pyplot.py", line 688, in savefig
res = fig.savefig(*args, **kwargs)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\figure.py", line 1539, in savefig
self.canvas.print_figure(*args, **kwargs)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\backend_bases.py", line 2230, in print_figure
**kwargs)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\backends\backend_svg.py", line 1206, in print_svg
return self._print_svg(filename, svgwriter, fh_to_close, **kwargs)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\backends\backend_svg.py", line 1234, in _print_svg
self.figure.draw(renderer)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\figure.py", line 1133, in draw
func(*args)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\axes\_base.py", line 2304, in draw
a.draw(renderer)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\legend.py", line 482, in draw
self._legend_box.draw(renderer)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\offsetbox.py", line 286, in draw
c.draw(renderer)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\offsetbox.py", line 286, in draw
c.draw(renderer)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\offsetbox.py", line 286, in draw
c.draw(renderer)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\offsetbox.py", line 286, in draw
c.draw(renderer)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\offsetbox.py", line 867, in draw
self._text.draw(renderer)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\text.py", line 792, in draw
mtext=mtext)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\backends\backend_svg.py", line 1152, in draw_tex
self._draw_text_as_path(gc, x, y, s, prop, angle, ismath="TeX")
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\backends\backend_svg.py", line 957, in _draw_text_as_path
return_new_glyphs_only=True)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\textpath.py", line 346, in get_glyphs_tex
font.select_charmap(charmap_code)
RuntimeError: In select_charmap: Could not set the charmap
any ideas what's going wrong/ could be improved?
I also had the same issue, and I fixed it by upgrading matplotlib to 1.5.1. It seems to be related with Matplotlib trying to render some fonts and not catching an exception that should've been caught.
Related: https://github.com/matplotlib/matplotlib/pull/5770#issuecomment-168212746