matplotlib —— 注释及几何图形的绘制

可视化——matplotlib常用api(一)

可视化——matploblib常见api(二)

fig = plt.figure()
ax = fig.add_subplot(111)
t = np.arange(0, 5, .01)
y = np.cos(2*np.pi*t)
line, = ax.plot(t, y, lw=2)

1. Annotating text

这里写图片描述

import matplotlib.pyplot as plt
import numpy as np

def main():
	fig = plt.figure()
	ax = fig.add_subplot(111)
	
	t = np.arange(0, 5, .01)	
	y = np.cos(2*np.pi*t)
	
	line, = ax.plot(t, y, lw=2)
	
	ax.set_ylim([-2+.2, 2-.2])
	ax.annotate('local max', xy=(3, 0), xytext=(3.5, 1.5), arrowprops=dict(facecolor='k', shrink=.05))
	plt.show()
if __name__ == '__main__':
	main()

2. 有规律的在figure中写东西

规律自然用到循环;

for i, (param, true, est) in enumerate(zip('ABCD', [A, B, C, D], plesq[0])):
	plt.text(10, 3-i*.5, '{} = {:.2f}, est({}) = {:.2f}'.format(param, true, param, est))
				# text的前两个参数是需要根据图像的布局反复调整的

这里写图片描述

3. 画圆(矩形、椭圆)

from matploblib.patches import Cicle, Ellipse
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ell1 = Ellipse(xy=(.0, .0), width=4, height=8, angle=30, facecolor='y', alpha=.3)
cir1 = Circle(xy=(.0, .0), radius=2, alpha=.4)
					# alpha的设置很重要,否则画出来的图会很丑
ax.add_patch(ell1)
ax.add_patch(cir1)
x, y = 0, 0
ax.plot(x, y, 'ro')
ax.axis('scaled')
plt.show()

4. 饼状图

5. 三角形

  • 描点连线,起点和终点相同
triangle1 = ((0, sqrt(3)/2), (1, 3*sqrt(3)/2), (2, sqrt(3)/2), (0, sqrt(3)/2))
triangle2 = ((0, sqrt(3)), (1, 0), (2, sqrt(3)), (0, sqrt(3)))
plt.plot([e[0] for e in triangle1], [e[1] for e in triangle1],
         [e[0]for e in triangle2], [e[1] for e in triangle2], 'b', lw=3)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

五道口纳什

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值