详解Matplotlib画图双纵坐标轴配置及节制配置时刻名目
plt.xticks(pd.date_range(demo0719.index[0],demo0719.index[-1],freq='1min')) 纵坐标配置表现百分比 import matplotlib.ticker as mtick
fmt='%.2f%%'
yticks = mtick.FormatStrFormatter(fmt)
ax2.yaxis.set_major_formatter(yticks) 常识点 在matplotlib中,整个图像为一个Figure工具。在Figure工具中可以包括一个,可能多个Axes工具。每个Axes工具都是一个拥有本身坐标体系的画图地区。其逻辑相关如下: 一个Figure对应一张图片。 Title为问题。Axis为坐标轴,Label为坐标轴标注。Tick为刻度线,Tick Label为刻度注释。 Title为问题。Axis为坐标轴,Label为坐标轴标注。Tick为刻度线,Tick Label为刻度注释。 add_subplot() 官网matplotlib.pyplot.figure pyplot.figure()是返回一个Figure工具的,也就是一张图片。 add_subplot(args, *kwargs) The Axes instance will be returned. twinx() matplotlib.axes.Axes method2 ax = twinx() create a twin of Axes for generating a plot with a sharex x-axis but independent y axis. The y-axis of self will have ticks on left and the returned axes will have ticks on the right. 意思就是,建设了一个独立的Y轴,共享了X轴。双坐标轴! 相同的尚有twiny() ax1.xaxis.set_major_formatter set_major_formatter(formatter) Set the formatter of the major ticker ACCEPTS: A Formatter instance DateFormatter() class matplotlib.dates.DateFormatter(fmt, tz=None) 这是一个类,建设一个时刻名目标实例。 strftime要领(传入名目化字符串)。 strftime(dt, fmt=None)
Refer to documentation for datetime.strftime.
fmt is a strftime() format string. FormatStrFormatter() class matplotlib.ticker.FormatStrFormatter(fmt) Use a new-style format string (as used by str.format()) to format the tick. The field formatting must be labeled x 界说字符串名目。 plt.xticks matplotlib.pyplot.xticks(args, *kwargs) # return locs, labels where locs is an array of tick locations and # labels is an array of tick labels. locs, labels = xticks()
# set the locations of the xticks xticks( arange(6) )
# set the locations and labels of the xticks xticks( arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue') ) (编辑:湖南网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |