修改python plot折线图的坐标轴刻度方法
作者:liangyhgood 时间:2021-06-24 09:09:43
修改python plot折线图的坐标轴刻度,这里修改为整数:
代码如下:
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()
可以发现,通过上面的方法可以自定义x轴的刻度显示为其他样式,比如根据时间显示。只需要修改为:
plt.xticks(pd.date_range(‘2014-09-01','2014-09-30'),rotation=90)#设置时间标签显示格式
如果希望保留小数点后一位,可以这样:
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()
来源:https://blog.csdn.net/liangyihuai/article/details/79338220
标签:python,plot,刻度
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
30万条数据,搜索文本字段的各种方式对比
2010-05-02 10:17:00
python打印9宫格、25宫格等奇数格 满足横竖斜相加和相等
2023-08-27 07:55:11
![](https://img.aspxhome.com/file/2023/7/72977_0s.jpg)
Python tkinter 多选按钮控件 Checkbutton方法
2022-12-31 08:38:46
![](https://img.aspxhome.com/file/2023/0/87570_0s.png)
div中class与id的区别及应用
2007-09-22 08:37:00
show一下刚做的系统登录界面
2008-09-13 19:13:00
![](https://img.aspxhome.com/file/UploadPic/20089/13/2008913191851666s.png)
在弹出窗口用POST提交数据
2010-02-24 09:39:00
Python爬虫采集微博视频数据
2023-08-11 16:01:03
![](https://img.aspxhome.com/file/2023/2/101012_0s.jpg)
MySQL与PHP的基础与应用专题之自连接
2023-11-14 08:52:37
![](https://img.aspxhome.com/file/2023/3/77203_0s.png)
Python实现将n个点均匀地分布在球面上的方法
2021-02-21 20:56:33
![](https://img.aspxhome.com/file/2023/1/107081_0s.png)
Python Pandas工具绘制数据图使用教程
2023-02-08 01:16:40
![](https://img.aspxhome.com/file/2023/3/72003_0s.png)
CentOS 7 安装python3.7.1的方法及注意事项
2023-03-10 21:23:53
正则表达式的基本概念
2007-10-17 21:07:00
简单了解django文件下载方式
2022-10-31 08:48:32
Python自动扫雷实现方法
2023-11-19 19:04:55
php动态函数调用方法
2023-11-15 00:18:30
详解MySQL数据库安全配置
2010-01-26 15:19:00
安装PyTorch的详细过程记录
2023-05-12 07:50:12
![](https://img.aspxhome.com/file/2023/1/103481_0s.png)
CSS的书写顺序规范
2008-06-12 13:51:00
一种特别简单的MySQL数据库安装方法
2008-12-17 15:30:00
ubuntu下简单配置mysql数据库
2009-07-31 09:17:00