修改python plot折線圖的坐標軸刻度方法
修改python plot折線圖的坐標軸刻度,這里修改為整數(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ù)點后一位,可以這樣:

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折線圖的坐標軸刻度方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
在Python中實現(xiàn)函數(shù)重載的示例代碼
這篇文章主要介紹了在Python中實現(xiàn)函數(shù)重載的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-12-12
Flask的圖形化管理界面搭建框架Flask-Admin的使用教程
Flask-Admin是一個為Python的Flask框架服務的微型框架,可以像Django-Admin那樣為用戶生成Model層面的數(shù)據(jù)管理界面,接下來就一起來看一下Flask的圖形化管理界面搭建框架Flask-Admin的使用教程2016-06-06
numpy矩陣乘法中的multiply,matmul和dot的使用
本文主要介紹了numpy矩陣乘法中的multiply,matmul和dot的使用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-02-02
pymysql實現(xiàn)增刪改查的操作指南(python)
python中可以使用pymysql來MySQL數(shù)據(jù)庫的連接,并實現(xiàn)數(shù)據(jù)庫的各種操作,這篇文章主要給大家介紹了關于pymsql實現(xiàn)增刪改查的相關資料,需要的朋友可以參考下2021-05-05

