matplotlib表示图像太大而不是

时间:2023-01-25 10:52:41

I'm doing this plotting in Jupyter Notebook:

我正在Jupyter笔记本中进行这种策划:

fig = plt.figure()
fig.suptitle("{0} nodes".format(i*4))
print("put suptitle")

fig.text(0,0,s="error: {0}".format(errors[i-1]))
print("put text")

plt.plot(means, np.zeros(means.shape), "go")
print(means.shape)

plt.plot(patterns_test, outputs, "r.", label="outputs")
print(patterns_test.shape, outputs.shape)

plt.plot(patterns_test, targets_test, "b.", label="targets")
print(patterns_test.shape, targets_test.shape)

plt.legend()
print("legend")

I've printed the shape of everything that it plotted, and the values returned are:

我已经打印了它绘制的所有内容的形状,返回的值是:

put suptitle
put text
(16,)
(62,) (62,)
(62,) (62,)
legend

Clearly nothing is large. But here's the error message:

显然没有什么是大的。但这是错误信息:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/anaconda3/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--> 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

/anaconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
    236 
    237     if 'png' in formats:
--> 238         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    239     if 'retina' in formats or 'png2x' in formats:
    240         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

/anaconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    120 
    121     bytes_io = BytesIO()
--> 122     fig.canvas.print_figure(bytes_io, **kw)
    123     data = bytes_io.getvalue()
    124     if fmt == 'svg':

/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2265                 orientation=orientation,
   2266                 bbox_inches_restore=_bbox_inches_restore,
-> 2267                 **kwargs)
   2268         finally:
   2269             if bbox_inches and restore_bbox:

/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
    505 
    506     def print_png(self, filename_or_obj, *args, **kwargs):
--> 507         FigureCanvasAgg.draw(self)
    508         renderer = self.get_renderer()
    509         original_dpi = renderer.dpi

/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in draw(self)
    420         Draw the figure using the renderer
    421         """
--> 422         self.renderer = self.get_renderer(cleared=True)
    423         # acquire a lock on the shared font cache
    424         RendererAgg.lock.acquire()

/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in get_renderer(self, cleared)
    442 
    443         if need_new_renderer:
--> 444             self.renderer = RendererAgg(w, h, self.figure.dpi)
    445             self._lastKey = key
    446         elif cleared:

/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in __init__(self, width, height, dpi)
     90         self.width = width
     91         self.height = height
---> 92         self._renderer = _RendererAgg(int(width), int(height), dpi, debug=False)
     93         self._filter_renderers = []
     94 

ValueError: Image size of 298022x298 pixels is too large. It must be less than 2^16 in each direction.

<matplotlib.figure.Figure at 0x1c139a84a8>

How can one sort this out?

如何解决这个问题呢?

2 个解决方案

#1


0  

I restarted Jupyter Notebook and the error was gone.

我重新启动了Jupyter Notebook,错误消失了。

#2


0  

In Jupyter Notebook you have Kernel -> Restart, try it first before restarting entire Jupyter Notebook. As well it may be caused by one of the other Jupyter tabs so Kernel -> Restart all the Jupyter tabs to release the memory.

在Jupyter Notebook中你有内核 - >重启,在重新启动整个Jupyter Notebook之前先试用它。同样,它可能是由其他Jupyter选项卡之一引起的,因此内核 - >重新启动所有Jupyter选项卡以释放内存。

#1


0  

I restarted Jupyter Notebook and the error was gone.

我重新启动了Jupyter Notebook,错误消失了。

#2


0  

In Jupyter Notebook you have Kernel -> Restart, try it first before restarting entire Jupyter Notebook. As well it may be caused by one of the other Jupyter tabs so Kernel -> Restart all the Jupyter tabs to release the memory.

在Jupyter Notebook中你有内核 - >重启,在重新启动整个Jupyter Notebook之前先试用它。同样,它可能是由其他Jupyter选项卡之一引起的,因此内核 - >重新启动所有Jupyter选项卡以释放内存。