1

现在我有一个名为 (1024, 1024) 的 NumPy 数组field,它存储在一个 .bigfile 中。我想通过使用在 xy 平面上可视化它的值plt.imshow。顺便说一句,最小值field0.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, 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
4

0 回答 0