您的位置:首页 > 编程语言 > PHP开发

用matplotlib设置标题、轴标签、刻度标签以及添加图例

2018-04-05 16:39 681 查看
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
fig=plt.figure()
ax=fig.add_subplot(1,1,1)
ax.plot(np.random.randn(1000).cumsum())
x_ticks=ax.set_xticks([0,250,500,750,1000])
x_labels=ax.set_xticklabels(["one","two","three","four","five"],rotation=30,fontsize="small")
y_ticks=ax.set_yticks([-80,-60,-40,-20,0])
y_labels=ax.set_yticklabels(["one","two","three","four","five"])
ax.set_title("my first matplotlib plot")
ax.set_xlabel("stages")
ax.set_ylabel("years")
plt.show()
#添加图例
fig=plt.figure()
ax1=fig.add_subplot(1,1,1)
ax1.plot(np.random.randn(1000).cumsum(),"k",label="one")
ax1.plot(np.random.randn(1000).cumsum(),"k--",label="two")
ax1.plot(np.random.randn(1000).cumsum(),"k.",label="three")
ax1.legend(loc="best")#ax.legend()或者plt.legend()
plt.show()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: