详解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') ) (编辑:晋中站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |