ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

matplotlib 常用小技巧

2021-08-30 10:04:02  阅读:221  来源: 互联网

标签:plot 常用 plt 技巧 示例 text matplotlib 25 marker


https://mp.weixin.qq.com/s/Ux66-omtEU6EWEWhjQnnyw

添加标题

plt.title('示例标题')

添加图上面的文字

x y 坐标,文本内容。


plt.text(1,2,'function y=x*x')

注释

xy :备注的坐标点

xytext :备注文字的坐标(默认为xy的位置)

arrowprops :在 xy 和 xytext 之间绘制一个箭头。


plt.annotate('示例注释',xy=(0,1),xytext=(1,2),arrowprops={'headwidth':10,'facecolor':'r'})

设置标题

plt.xlabel('示例x轴')

plt.ylabel('示例y轴')

添加图例

plt.legend(['1','2'])

color 可以为缩写 以及 RGB 十六进制数

plt.plot(x1,color='g')

plt.plot(x2,color='#FF00FF')

该表线条样式

marker = 'o' , '>' , 's'


plt.plot(x,marker='o')

plt.plot(x+1,marker='>')

plt.plot(x+2,marker='s')

marker 支持的类型:

‘.’:点(point marker)

‘,’:像素点(pixel marker)

‘o’:圆形(circle marker)

‘v’:朝下三角形(triangle_down marker)

‘^’:朝上三角形(triangle_up marker)

‘<‘:朝左三角形(triangle_left marker)

‘>’:朝右三角形(triangle_right marker)

‘1’:(tri_down marker)

‘2’:(tri_up marker)

‘3’:(tri_left marker)

‘4’:(tri_right marker)

‘s’:正方形(square marker)

‘p’:五边星(pentagon marker)

‘*’:星型(star marker)

‘h’:1号六角形(hexagon1 marker)

‘H’:2号六角形(hexagon2 marker)

‘+’:+号标记(plus marker)

‘x’:x号标记(x marker)

‘D’:菱形(diamond marker)

‘d’:小型菱形(thin_diamond marker)

‘|’:垂直线形(vline marker)

‘_’:水平线形(hline marker)

显示数学公式
使用 $ 内容 $


plt.text(2,4,r'$ \alpha \beta \pi \lambda \omega $',size=25)
plt.text(4,4,r'$ \sin(0)=\cos(\frac{\pi}{2}) $',size=25)
plt.text(2,2,r'$ \lim_{x \rightarrow y} \frac{1}{x^3} $',size=25)
plt.text(4,2,r'$ \sqrt[4]{x}=\sqrt{y} $',size=25)

网格线
plt.grid()


plt.grid(color='g',linewidth='1',linestyle='-.')

坐标轴刻度

x 和 y 轴
plt.locator_params(nbins=30)



x 轴

plt.locator_params("x",nbins=30)


 y 轴

plt.locator_params("y",nbins=20)

当 x 轴为日期时,进行日期自适应

x=pd.date_range('2020/01/01',periods=30)

plt.gcf().autofmt_xdate()

 

标签:plot,常用,plt,技巧,示例,text,matplotlib,25,marker
来源: https://www.cnblogs.com/hany-postq473111315/p/15204600.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有