Python 为什么在我运行'plt.savefig()'之后发生'ValueError:minvalue必须为正'?

Python 为什么在我运行'plt.savefig()'之后发生'ValueError:minvalue必须为正'?,python,matplotlib,imshow,savefig,Python,Matplotlib,Imshow,Savefig,现在我有一个名为field的(10241024)NumPy数组,它存储在一个.big文件中。我想通过使用plt.imshow在x-y平面上可视化它的值。顺便说一下,字段的最小值是0.0,最大值是89297.414 # plot in the linuxremote server import matplotlib as mpl mpl.use('Agg') import matplotlib.pyplot as plt import bigfile with bigfile.File('fi

现在我有一个名为
field
的(10241024)NumPy数组,它存储在一个.big文件中。我想通过使用
plt.imshow
在x-y平面上可视化它的值。顺便说一下,
字段
的最小值是
0.0
,最大值是
89297.414

# plot in the linuxremote server
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt

import bigfile

with bigfile.File('filename.bigfile') as bf:
     shape = bf['Field'].attrs['ndarray.shape']
     field = bf['Field'][:].reshape(shape)

plt.imshow(field, norm=mpl.colors.LogNorm());
plt.savefig('field.pdf')
此代码运行后,
ValueError:minvalue必须为正

我猜是最小值
0.0
导致了错误,所以我设置
字段+=0.001
。但是,它是无用的,错误仍然会发生


ValueError回溯(最近一次调用)
在里面
---->1 plt.savefig('field.pdf')
/savefig中的opt/miniconda3/lib/python3.8/site-packages/matplotlib/pyplot.py(*args,**kwargs)
841 def savefig(*参数,**kwargs):
842图=gcf()
-->843 res=图savefig(*args,**kwargs)
844 fig.canvas.draw_idle()#如果“transparent=True”重置颜色,则需要此选项
845返回res
/savefig中的opt/miniconda3/lib/python3.8/site-packages/matplotlib/figure.py(self、fname、transparent、**kwargs)
2309补丁。设置边缘颜色(“无”)
2310
->2311自我。画布。打印图形(fname,**kwargs)
2312
2313如果透明:
/打印图形中的opt/miniconda3/lib/python3.8/site-packages/matplotlib/backend_base.py(self、文件名、dpi、facecolor、edgecolor、方向、格式、bbox_英寸、pad_英寸、bbox_额外艺术家、后端、**kwargs)
2208
2209尝试:
->2210结果=打印方法(
2211文件名,
2212 dpi=dpi,
/包装中的opt/miniconda3/lib/python3.8/site-packages/matplotlib/backend_base.py(*args,**kwargs)
1637 kwargs.pop(arg)
1638
->1639返回函数(*args,**kwargs)
1640
1641返回包装器
/opt/miniconda3/lib/python3.8/site-packages/matplotlib/backends/backend\u pdf.py in print\u pdf(self、文件名、dpi、bbox\u inches\u restore、元数据)
2591渲染器PDF(文件、dpi、高度、宽度),
2592 bbox\u inches\u restore=bbox\u inches\u restore)
->2593自绘制(渲染器)
2594.finalize()
2595如果不存在(文件名,PdfPages):
/绘图包装中的opt/miniconda3/lib/python3.8/site-packages/matplotlib/artist.py(艺术家、渲染器、*args、**kwargs)
39.start_filter()
40
--->41返回绘制(艺术家、渲染器、*args、**kwargs)
42.最后:
43如果artist.get_agg_filter()不是None:
/绘图中的opt/miniconda3/lib/python3.8/site-packages/matplotlib/figure.py(self,渲染器)
1861
1862自补片绘制(渲染器)
->1863模拟图像。\绘制\列表\合成\图像(
1864渲染器,self,美工人员,self.suppressComposite)
1865
/opt/miniconda3/lib/python3.8/site-packages/matplotlib/image.py in_-draw_-list_-composition_图像(渲染器、父级、艺术家、抑制_-composite)
129如果没有\u复合或没有\u图像:
130对于一个艺术家:
-->131 a.draw(渲染器)
132其他:
133#将任何相邻图像合成在一起
/绘图包装中的opt/miniconda3/lib/python3.8/site-packages/matplotlib/artist.py(艺术家、渲染器、*args、**kwargs)
39.start_filter()
40
--->41返回绘制(艺术家、渲染器、*args、**kwargs)
42.最后:
43如果artist.get_agg_filter()不是None:
/包装中的opt/miniconda3/lib/python3.8/site-packages/matplotlib/cbook/deprecation.py(*内部参数,**内部参数)
409其他弃用附录,
410**夸尔格)
-->411返回函数(*内部参数,**内部参数)
412
413返回包装器
/绘图中的opt/miniconda3/lib/python3.8/site-packages/matplotlib/axes//u base.py(self、renderer、inframe)
2746.停止光栅化()
2747
->2748模拟图像。\绘制\列表\合成\图像(渲染器、自身、艺术家)
2749
2750渲染器。关闭_组(“轴”)
/opt/miniconda3/lib/python3.8/site-packages/matplotlib/image.py in_-draw_-list_-composition_图像(渲染器、父级、艺术家、抑制_-composite)
153图像组。附加(a)
154其他:
-->155个图像()
156 a.绘制(渲染器)
157个图像()
/flush_images()中的opt/miniconda3/lib/python3.8/site-packages/matplotlib/image.py
139图像组[0]。绘制(渲染器)
140 elif len(图像组)>1:
-->141数据,l,b=合成图像(图像组、渲染器、mag)
142如果data.size!=0:
143 gc=renderer.new_gc()
/复合图像(图像、渲染器、放大率)中的opt/miniconda3/lib/python3.8/site-packages/matplotlib/image.py
87箱=[]
88对于图像中的图像:
--->89数据,x,y,trans=图像。生成图像(渲染器,放大)
90如果数据不是无:
91 x*=放大倍数
/make_image中的opt/miniconda3/lib/python3.8/site-packages/matplotlib/image.py(self、渲染器、放大率、未采样)
920 clip=((self.get\u clip\u box()或self.axes.bbox)如果self.get\u clip\u on()
921 else self.figure.bbox)
-->922返回self.\u生成图像(self.\u A,bbox,转换的\u bbox,剪辑,
923放大率,未采样=未采样)
924
/opt/miniconda3/lib/python3.8/site-packages/matplotlib/image.py in\u make\u image(self、A、in\u bbox、out\u bbox、clip\u bbox、放大、未采样、圆形到像素\u边框)
539 vmax=vrange[1],
540                                        ):
--> 541
ValueError                                Traceback (most recent call last)
<ipython-input-20-a10e1bbeb736> in <module>
----> 1 plt.savefig('field.pdf')

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/pyplot.py in savefig(*args, **kwargs)
    841 def savefig(*args, **kwargs):
    842     fig = gcf()
--> 843     res = fig.savefig(*args, **kwargs)
    844     fig.canvas.draw_idle()   # need this if 'transparent=True' to reset colors
    845     return res

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/figure.py in savefig(self, fname, transparent, **kwargs)
   2309                 patch.set_edgecolor('none')
   2310 
-> 2311         self.canvas.print_figure(fname, **kwargs)
   2312 
   2313         if transparent:

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2208 
   2209             try:
-> 2210                 result = print_method(
   2211                     filename,
   2212                     dpi=dpi,

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/backend_bases.py in wrapper(*args, **kwargs)
   1637             kwargs.pop(arg)
   1638 
-> 1639         return func(*args, **kwargs)
   1640 
   1641     return wrapper

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/backends/backend_pdf.py in print_pdf(self, filename, dpi, bbox_inches_restore, metadata)
   2591                 RendererPdf(file, dpi, height, width),
   2592                 bbox_inches_restore=bbox_inches_restore)
-> 2593             self.figure.draw(renderer)
   2594             renderer.finalize()
   2595             if not isinstance(filename, PdfPages):

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     39                 renderer.start_filter()
     40 
---> 41             return draw(artist, renderer, *args, **kwargs)
     42         finally:
     43             if artist.get_agg_filter() is not None:

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/figure.py in draw(self, renderer)
   1861 
   1862             self.patch.draw(renderer)
-> 1863             mimage._draw_list_compositing_images(
   1864                 renderer, self, artists, self.suppressComposite)
   1865 

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    129     if not_composite or not has_images:
    130         for a in artists:
--> 131             a.draw(renderer)
    132     else:
    133         # Composite any adjacent images together

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     39                 renderer.start_filter()
     40 
---> 41             return draw(artist, renderer, *args, **kwargs)
     42         finally:
     43             if artist.get_agg_filter() is not None:

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/cbook/deprecation.py in wrapper(*inner_args, **inner_kwargs)
    409                          else deprecation_addendum,
    410                 **kwargs)
--> 411         return func(*inner_args, **inner_kwargs)
    412 
    413     return wrapper

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
   2746             renderer.stop_rasterizing()
   2747 
-> 2748         mimage._draw_list_compositing_images(renderer, self, artists)
   2749 
   2750         renderer.close_group('axes')

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    153                 image_group.append(a)
    154             else:
--> 155                 flush_images()
    156                 a.draw(renderer)
    157         flush_images()

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/image.py in flush_images()
    139                 image_group[0].draw(renderer)
    140             elif len(image_group) > 1:
--> 141                 data, l, b = composite_images(image_group, renderer, mag)
    142                 if data.size != 0:
    143                     gc = renderer.new_gc()

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/image.py in composite_images(images, renderer, magnification)
     87     bboxes = []
     88     for image in images:
---> 89         data, x, y, trans = image.make_image(renderer, magnification)
     90         if data is not None:
     91             x *= magnification

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/image.py in make_image(self, renderer, magnification, unsampled)
    920         clip = ((self.get_clip_box() or self.axes.bbox) if self.get_clip_on()
    921                 else self.figure.bbox)
--> 922         return self._make_image(self._A, bbox, transformed_bbox, clip,
    923                                 magnification, unsampled=unsampled)
    924 

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/image.py in _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification, unsampled, round_to_pixel_border)
    539                                        vmax=vrange[1],
    540                                        ):
--> 541                     output = self.norm(resampled_masked)
    542             else:
    543                 if A.shape[2] == 3:

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/colors.py in __call__(self, value, clip)
   1190 
   1191         self.autoscale_None(result)
-> 1192         self._check_vmin_vmax()
   1193         vmin, vmax = self.vmin, self.vmax
   1194         if vmin == vmax:

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/colors.py in _check_vmin_vmax(self)
   1179             raise ValueError("minvalue must be less than or equal to maxvalue")
   1180         elif self.vmin <= 0:
-> 1181             raise ValueError("minvalue must be positive")
   1182 
   1183     def __call__(self, value, clip=None):

ValueError: minvalue must be positive