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()