您现在的位置是:网站首页> 编程资料编程资料
Python matplotlib绘图时指定图像大小及放大图像详解_python_
2023-05-26
331人已围观
简介 Python matplotlib绘图时指定图像大小及放大图像详解_python_
matplotlib绘图时是默认的大小,有时候默认的大小会感觉图片里的内容都被压缩了,解决方法如下。
先是原始代码:
from matplotlib import pyplot as plt plt.figure(figsize=(1,1)) x = [1,2,3] plt.plot(x, x) plt.show()
关键的代码是plt.figure(figsize=(1,1)),生成的图片如下

修改代码,放大图片:
from matplotlib import pyplot as plt plt.figure(figsize=(10,10)) x = [1,2,3] plt.plot(x, x) plt.show()
这时候横坐标和纵坐标都放大了10倍:

如果想要指定像素,可以这么做:
from matplotlib import pyplot as plt plt.figure(dpi=80) x = [1,2,3] plt.plot(x, x) plt.show()

更多参考资料:python - How do you change the size of figures drawn with matplotlib? - Stack Overflow
附:matplotlib绘图时横纵坐标和图例的字体大小如何设置
横纵坐标字体大小调节:
通过fontsize可以进行调节
ax1.set_ylabel("AUC",fontsize=20) ax2.set_ylabel("Logloss",fontsize=20) 图例字体大小调节:
在plt.legend中加一个
prop={"size":18,"weight":"black"} 即可
总结
到此这篇关于Python matplotlib绘图时指定图像大小及放大图像的文章就介绍到这了,更多相关Python matplotlib绘图图像大小内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
您可能感兴趣的文章:
相关内容
- python中如何设置list步长_python_
- Python处理mat文件的三种方式小结_python_
- PyTorch搭建双向LSTM实现时间序列负荷预测_python_
- 关于Torch torchvision Python版本对应关系说明_python_
- python如何生成任意n阶的三对角矩阵_python_
- PyTorch搭建LSTM实现多变量多步长时序负荷预测_python_
- PyTorch搭建LSTM实现多变量时序负荷预测_python_
- Python学习之名字,作用域,名字空间_python_
- Python自动化办公之Word文件内容的读取_python_
- PyTorch深度学习LSTM从input输入到Linear输出_python_
