1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| import matplotlib.lines as mlines import matplotlib.pyplot as plt import numpy as np import pandas as pd
plt.rcParams['font.sans-serif'] = ['SimHei'] plt.rcParams['axes.unicode_minus'] = False plt.figure() x=pd.Series(np.exp(np.arange(20))) p1=x.plot(label=u'原始数据图') plt.ylabel('正常坐标') x2=pd.Series(np.log10(x)) p2=x2.plot(secondary_y=True,style='--',color='r',) plt.yticks(plt.yticks()[0],['$10^%d$'%w for w in range(len(plt.yticks()[0]))])
plt.ylabel('指数坐标') blue_line = mlines.Line2D([],[],linestyle='-',color='blue',markersize=2, label=u'原始数据图') red_line= mlines.Line2D([],[],linestyle='--',color='red',markersize=2, label=u'对数数据图') plt.legend(handles=[blue_line,red_line],loc='upper left') plt.grid(True) plt.show()
|