|
import random |
|
import matplotlib.pyplot as plt |
|
|
|
|
|
plt.rcParams['font.sans-serif'] = ['SimHei'] |
|
|
|
""" |
|
添加文本标签: |
|
matplotlib.pyplot.text(x,y,s,**kwargs) |
|
s: 显示的内容 |
|
|
|
设置标题和图例: |
|
matplotlib.pyplot.title() |
|
matplotlib.pyplot.legend() |
|
|
|
通用绘图参数 说明 |
|
fontsize 字体大小 |
|
ha 水平对齐方式 |
|
va 垂直对齐方式 |
|
|
|
位置 描述 位置 描述 位置 描述 |
|
best 自适应 upper right 右上方 upper left 左上方 |
|
lower right 右下方 lower left 左下方 right 右侧 |
|
center left 左中间 center right 右中间 upper center 上中间 |
|
center 正中央 lower center 下中间 |
|
|
|
""" |
|
x = [i for i in range(1, 11)] |
|
y = [random.randint(1, 10) for _ in range(10)] |
|
|
|
plt.plot(x, y, marker='o', mfc='w') |
|
|
|
month = [str(i) + '月' for i in range(1, 11)] |
|
|
|
plt.xticks(range(1, 11), month) |
|
plt.yticks(range(1, 11)) |
|
|
|
|
|
for a, b in zip(x, y): |
|
plt.text(a, b, b, ha='center', va='center', fontsize=12, color='r') |
|
|
|
|
|
plt.title('测试练习折线图', fontsize=18) |
|
|
|
|
|
plt.legend(('销售次数',)) |
|
|
|
plt.show() |
|
|