修改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),通過(guò)上面的方法可以自定義x軸的刻度顯示為其他樣式,比如根據(jù)時(shí)間顯示。只需要修改為:
plt.xticks(pd.date_range(‘2014-09-01','2014-09-30'),rotation=90)#設(shè)置時(shí)間標(biāo)簽顯示格式
如果希望保留小數(shù)點(diǎn)后一位,可以這樣:
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)軸刻度方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python一行代碼對(duì)話ChatGPT實(shí)現(xiàn)詳解
這篇文章主要為大家介紹了Python一行代碼對(duì)話ChatGPT實(shí)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03python 請(qǐng)求服務(wù)器的實(shí)現(xiàn)代碼(http請(qǐng)求和https請(qǐng)求)
本篇文章主要介紹了python 請(qǐng)求服務(wù)器的實(shí)現(xiàn)代碼(http請(qǐng)求和https請(qǐng)求),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-05-05Python修改Excel數(shù)據(jù)的實(shí)例代碼
Python修改Excel數(shù)據(jù)的方法。2013-11-11Python寫的創(chuàng)建文件夾自定義函數(shù)mkdir()
這篇文章主要介紹了Python寫的創(chuàng)建文件夾自定義函數(shù)mkdir(),文件夾操作是編程中經(jīng)常需要的,mkdir函數(shù)更是經(jīng)典中的經(jīng)典,需要的朋友可以參考下2014-08-08Python的CGIHTTPServer交互實(shí)現(xiàn)詳解
本篇文章主要給大家詳細(xì)分析了Python的CGIHTTPServer交互實(shí)現(xiàn)過(guò)程以及相關(guān)代碼分享,有興趣的參考學(xué)習(xí)下。2018-02-02Python數(shù)據(jù)清洗工具之Numpy的基本操作
Numpy的操作對(duì)象是一個(gè)ndarray,所以在使用這個(gè)庫(kù)進(jìn)行計(jì)算的時(shí)候需要將數(shù)據(jù)進(jìn)行轉(zhuǎn)化,這篇文章主要介紹了Python數(shù)據(jù)清洗工具之Numpy的基本操作,需要的朋友可以參考下2021-04-04