为什么在我运行`plt.savefig`之后发生“ ValueError:minvalue必须为正”?

问题描述

现在我有一个名为field的(1024,1024)NumPy数组,该数组存储在.bigfile中。我想使用plt.imshow在x-y平面上可视化其值。顺便说一下,field的最小值是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 must be positive

我猜测最小值0.0导致了错误,因此我设置了field += 0.001。但是,它是没有用的,并且仍然会发生错误


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,bBox_inches_restore,Metadata)
   2591                 RendererPdf(file,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,**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,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,**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,inframe)
   2746             renderer.stop_rasterizing()
   2747 
-> 2748         mimage._draw_list_compositing_images(renderer,artists)
   2749 
   2750         renderer.close_group('axes')

/opt/miniconda3/lib/python3.8/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer,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,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,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,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,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,clip=None):

ValueError: minvalue must be positive

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...