Python matplotlab库使用方法及注意事项
2020-01-11 13:26
113 查看
1.Python使用Matplotlib模块时坐标轴标题中文及各种特殊符号显示方法
import matplotlib.pyplot as plt t = arange(-4*pi, 4*pi, 0.01) y = sin(t)/t plt.plot(t, y) plt.title('www.jb51.net - test') plt.xlabel(u'\u2103',fontproperties='SimHei') #在这里,u'\u2103'是摄氏度,前面的u代表unicode,而引号里的内容,是通过在网上查找“℃”这一个符号的unicode编码得到的。这里的“摄氏度”是中文,要显示的话需要在后面加上fontproperties属性即可,这里设置的字体为黑体。 plt.ylabel(u'幅度',fontproperties='SimHei')#也可以直接显示中文。 plt.show()
2.如何将已知折线平滑化或者插值,有没有合适的函数
使用 scipy 库中的 interpolate 中的 interp1d.
平滑前,
import numpy as np from scipy import interpolate import matplotlib.pyplot as plt x = np.linspace(-np.pi, np.pi, 10) y = np.sin(x) plt.plot(x, y)
如图
平滑后,
f = interpolate.interp1d(x, y, kind='cubic') nx = np.linspace(-np.pi, np.pi, 30) ny = f(nx) plt.plot(nx, ny)
如图
3.使用matplotlib的savefig保存时图片保存不清晰以及不完整的问题
关于savefig的相关参数:
savefig(fname, dpi=None, facecolor=‘w’, edgecolor=‘w’,orientation=‘portrait’, papertype=None, format=None, transparent=False, bbox_inches=None, pad_inches=0.1,frameon=None, metadata=None)
图片不清晰,需要指定dpi,
图片保存大小问题,设置bbox_inches=‘tight’
(bbox_inches:可选bbox英寸。只保存图形的给定部分。如果“紧”,试着找出数字的紧框。如果没有,请使用savefig.bbox)
plt.savefig("data/temp.png",dpi=500,bbox_inches = 'tight')#解决图片不清晰,不完整的问题
如需更多关于画图保存的问题,可以参考Python绘图问题:Matplotlib中指定图片大小和像素。
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- Python中random.shuffle函数使用方法及注意事项
- python关于BIF、标准库方法使用的注意事项总结
- jdom中使用setAttribute(Attribute attribute)方法设置属性的注意事项
- ScrolledComposite使用方法及注意事项
- python threadpool使用注意事项
- C程序员使用Python的注意事项
- python3之IDLE使用注意事项
- jquery load事件(callback/data)使用方法及注意事项
- java.util.List接口的方法subList()的使用注意事项
- SharePoint中使用SilverLight的注意事项及SilverLight显示空白的解决方法
- Android使用Parcelable传递对象方法及注意事项
- 注释的使用方法及注意事项和汇编语言的使用
- boost.python vector_indexing_suite 使用注意事项
- EGOImageView的使用方法及注意事项
- C++中typename关键字的使用方法和注意事项
- 字符串strip()方法注意事项 分类: python基础学习 2013-08-16 12:01 422人阅读 评论(0) 收藏
- PRTG流量监控基本安装和使用方法及注意事项
- cvFloodFill的使用方法和注意事项。
- C++中typename关键字的使用方法和注意事项
- 苹果leopard安装PythonCard和wxPython的方法及注意事项