matplotlib text 文字处理

1.4.处理文字
text()命令可以在任意的位置添加文字,xlabel(),ylabel(),title()分别是添加x轴,y轴标签和标题。

import numpy as np
import matplotlib.pyplot as plt
# Fixing random state for reproducibility
np.random.seed(19680801)
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
# the histogram of the data
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75)
plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title('Histogram of IQ')
plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
plt.axis([40, 160, 0, 0.03])
plt.grid(True)
plt.show()

这里写图片描述
所有的text()命令会返回一个matplotlib.text.Text实例,通过属性或者setp()来改变他们。
t = plt.xlabel(‘my data’, fontsize=14, color=’red’)
1.4.1 使用数学表达式

plt.title(r'$\sigma_i=15$')

前置的r是指定它后面的字符串是原始的字符串,然后用$包裹表示中间的是数学表达式,\表示转译具体的数学符号。
4.2 注释
annotate()方法提供了一个注释的方法。
annotate(string,xy,xytest,arrowprops)

import numpy as np
import matplotlib.pyplot as plt
ax = plt.subplot(111)
t = np.arange(0.0, 5.0, 0.01)
s = np.cos(2*np.pi*t)
line, = plt.plot(t, s, lw=2)
plt.annotate('local max', xy=(2, 1), xytext=(3, 1.5),
arrowprops=dict(facecolor='black', shrink=0.05),
)
plt.ylim(-2,2)
plt.show()

这里写图片描述

默认的情况下,xy和xytext使用的坐标是数据的坐标,你也可以指定其他的坐标系统。

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值