Skip to main content
 首页 » 编程设计

python之MATPLOTLIB 中的 read_png 是模糊的

2024年11月01日9luoye11

我正在使用以下代码将 .png 拼接成来自 MATPLOTLIB 的散点图。不幸的是,插图的图像质量很糟糕。我该如何解决这个问题?

  png_file = open("blah.png",'r') 
  arr_lena = read_png(png_file) 
 
  imagebox = OffsetImage(arr_lena, zoom=0.2) 
 
  ab = AnnotationBbox(imagebox, (99.17,68.006), 
      xybox=(100,0.), 
      xycoords='data', 
      boxcoords="offset points", 
      pad=0.5, 
      arrowprops=dict(arrowstyle="->", 
        connectionstyle="angle,angleA=0,angleB=90,rad=3") 
      ) 
 
 
  ax.add_artist(ab) 

请您参考如下方法:

保存图形时,可以设置dpi。这修复了 png 图像的质量。例如:

plt.savefig('my_figure.pdf', bbox_inches='tight', dpi=400)