python - 如何在另一个已保存的文件上显示图形? (Python)

标签 python matplotlib

我正在使用pylab。那么它是使用 from show_graph import display 吗?

from pylab import *
from numpy import outer
from show_graph import display
rc('text', usetex=False)
a=outer(arange(0,1,0.01),ones(10))
figure(figsize=(10,5))
subplots_adjust(top=0.8,bottom=0.05,left=0.01,right=0.99)
maps=[m for m in cm.datad if not m.endswith("_r")]
maps.sort()
l=len(maps)+1
for i, m in enumerate(maps):
    subplot(1,l,i+1)
    axis("off")
    imshow(a,aspect='auto',cmap=get_cmap(m),origin="lower")
    title(m,rotation=90,fontsize=10)
savefig("colormaps.png",dpi=100,facecolor='gray')
display("colormaps.png")

但是当我尝试运行时,它说没有名为 show_graph 的模块

最佳答案

您应该删除 from show_graph import display,因为此导入会引发 ImportError。然后您保存并显示绘图的代码可以例如:像这样

from pylab import *
from numpy import outer
rc('text', usetex=False)
a=outer(arange(0,1,0.01),ones(10))
figure(figsize=(10,5))
subplots_adjust(top=0.8,bottom=0.05,left=0.01,right=0.99)
maps=[m for m in cm.datad if not m.endswith("_r")]
maps.sort()
l=len(maps)+1
for i, m in enumerate(maps):
    subplot(1,l,i+1)
    axis("off")
    imshow(a,aspect='auto',cmap=get_cmap(m),origin="lower")
    title(m,rotation=90,fontsize=10)
savefig("colormaps.png",dpi=100,facecolor='gray')
show()

关于python - 如何在另一个已保存的文件上显示图形? (Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16501188/

相关文章:

javascript - 如何在 FLASK 中使用 ajax 发布数据后渲染模板?

python - 'unicode'对象没有属性 'saveAsTextFile'

python - 如何在 FastAPI 中使用默认参数运行 python 脚本?

python - 在第一个图形仍然打开时用 matplotlib 绘制第二个图形

python - 在 python 中绘制 YoY 价格相关性。 (绘制 Dataframe 行的相关性)

python - SQLAlchemy 默认日期时间

python - 如何OCR低分辨率图像

python - 共享轴 (twinx) 隐藏 y 轴值

python - seaborn 因子图的线型和 x_jitter

python - 如何更改Python中条形图的顺序?