python - MATPLOTLIB 中的 read_png 是模糊的

标签 python matplotlib

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

see blurry inset image

  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)

关于python - MATPLOTLIB 中的 read_png 是模糊的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21393588/

相关文章:

python - 无法在 Ubuntu Linux 中使用 pip 安装 Python 包 : InsecurePlatformWarning, SSLError,tlsv1 警报协议(protocol)版本

python - 如何重复一个函数n次

python - 设置每个实例 __call__ 的方法?

python - 如何在python动画中添加图例/标签

python - 绘制 python 日期时间的累积图

python - 静态文件在生产中加载但不在开发中

python - BigQuery : result set in UI and from API have different number of rows. 为什么?

Python实时绘制ROS数据

matplotlib - 在matplotlib basemap 中使用比例尺

python - 如何在 matplotlib/pylab 图表中水平打印 Y 轴标签?