在数据可视化过程中,使用annotate()方法在图片中使用文字来注释图中的一些特征。
特别注意两点:
1.被注释地方,使用坐标xy=(x,y)给出;
2.插入文本的地方,使用坐标xytext=(x,y)给出。
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(-10, 11, 1)
y = x * x
plt.plot(x, y)
# 添加注释
# 第一个参数是注释的内容
# xy设置箭头尖的坐标
# xytext设置注释内容显示的起始位置
# arrowprops 用来设置箭头
# facecolor 设置箭头的颜色
# headlength 箭头的头的长度
# headwidth 箭头的宽度
# width 箭身的宽度
plt.annotate(u"This is a zhushi", xy = (0, 1), xytext = (-4, 50),\
arrowprops = dict(facecolor = "r", headlength = 10, headwidth = 30, width = 20))
# 可以通过设置xy和xytext中坐标的值来设置箭身是否倾斜
plt.show()
---------------------
原文:https://blog.csdn.net/you_are_my_dream/article/details/53454549
中文显示问题:
plt.bar([2,4,6,8],[1,3,5,7])
plt.xlabel('偶数')
plt.ylabel('奇数')
plt.show()
图形结果:label中文显示不出来,乱码原因就是字体默认设置并木有