修改python plot折線圖的坐標(biāo)軸刻度方法
修改python plot折線圖的坐標(biāo)軸刻度,這里修改為整數(shù):

代碼如下:
from matplotlib import pyplot as plt
import matplotlib.ticker as ticker
import numpy as np
def std_plot():
overall_std = [34.369, 21.366, 16.516, 11.151]
max_std = [36.769, 21.794, 14.390, 4.684]
plt.figure()
plt.plot(overall_std, label='average_std')
plt.plot(max_std, label='max_std')
plt.legend()
plt.xlabel('window')
plt.ylabel('std')
plt.xticks(range(len(max_std)))
# plt.gca().xaxis.set_major_formatter(ticker.FormatStrFormatter('%1.1f'))
plt.show()
std_plot()
可以發(fā)現(xiàn),通過上面的方法可以自定義x軸的刻度顯示為其他樣式,比如根據(jù)時間顯示。只需要修改為:
plt.xticks(pd.date_range(‘2014-09-01','2014-09-30'),rotation=90)#設(shè)置時間標(biāo)簽顯示格式
如果希望保留小數(shù)點后一位,可以這樣:

from matplotlib import pyplot as plt
import matplotlib.ticker as ticker
import numpy as np
def std_plot():
overall_std = [34.369, 21.366, 16.516, 11.151]
max_std = [36.769, 21.794, 14.390, 4.684]
plt.figure()
plt.plot(overall_std, label='average_std')
plt.plot(max_std, label='max_std')
plt.legend()
plt.xlabel('window')
plt.ylabel('std')
# plt.xticks(range(len(max_std)))
plt.gca().xaxis.set_major_formatter(ticker.FormatStrFormatter('%1.1f'))
plt.show()
std_plot()
以上這篇修改python plot折線圖的坐標(biāo)軸刻度方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
python 請求服務(wù)器的實現(xiàn)代碼(http請求和https請求)
本篇文章主要介紹了python 請求服務(wù)器的實現(xiàn)代碼(http請求和https請求),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-05-05
Python寫的創(chuàng)建文件夾自定義函數(shù)mkdir()
這篇文章主要介紹了Python寫的創(chuàng)建文件夾自定義函數(shù)mkdir(),文件夾操作是編程中經(jīng)常需要的,mkdir函數(shù)更是經(jīng)典中的經(jīng)典,需要的朋友可以參考下2014-08-08
Python的CGIHTTPServer交互實現(xiàn)詳解
本篇文章主要給大家詳細(xì)分析了Python的CGIHTTPServer交互實現(xiàn)過程以及相關(guān)代碼分享,有興趣的參考學(xué)習(xí)下。2018-02-02
Python數(shù)據(jù)清洗工具之Numpy的基本操作
Numpy的操作對象是一個ndarray,所以在使用這個庫進(jìn)行計算的時候需要將數(shù)據(jù)進(jìn)行轉(zhuǎn)化,這篇文章主要介紹了Python數(shù)據(jù)清洗工具之Numpy的基本操作,需要的朋友可以參考下2021-04-04

