基于matplotlib xticks用法详解
作者:chuang94 时间:2022-10-09 12:51:31
这个坐标轴变名用法,我真服气了,我在网上看大家写的教程,看的头晕,也没看懂他们写xtick到底怎么用的,最后找到官方教程,看了一个例子,over
xticks到底有什么用,其实就是想把坐标轴变成自己想要的样子
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [1, 4, 9, 6]
labels = ['Frogs', 'Hogs', 'Bogs', 'Slogs']
plt.plot(x, y)
# You can specify a rotation for the tick labels in degrees or with keywords.
plt.xticks(x, labels, rotation='vertical')
# Pad margins so that markers don't get clipped by the axes
plt.margins(0.2)
# Tweak spacing to prevent clipping of tick-labels
plt.subplots_adjust(bottom=0.15)
plt.show()
我们看下结果
大家看,坐标轴变成了我们想要的样子,那么这个代码是怎么实现的了
其实非常简单,先画图,然后改变坐标轴名字
其实xticks就类似覆盖吧,而且覆盖的数组长度要和原来横轴的坐标长度一致
补充知识:plt.xticks中的参数代表的含义与scatter等函数中的变量的意义
plt.xticks([0,1],[1,2],rotation=0)
[0,1]代表x坐标轴的0和1位置,[2,3]代表0,1位置的显示lable,rotation代表lable显示的旋转角度。
values=data[‘values']
plt.scatter(values[:,0],values[:,2],marker=‘o')#以数据的第零列做x轴,第三列做y轴,来描绘散点图
来源:https://blog.csdn.net/weixin_35834894/article/details/98874947
标签:matplotlib,xticks
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
如何创建SQL Server 2000故障转移群集
2009-02-13 17:18:00
Mysql my.ini 配置文件详解
2024-01-28 06:16:57
Vue中插槽slot的使用方法与应用场景详析
2023-07-02 17:04:11
![](https://img.aspxhome.com/file/2023/6/139916_0s.png)
MySQL转义字符的实际应用
2010-08-31 14:55:00
asp下查询xml的实现代码
2011-04-19 10:37:00
用javascript代替marquee的滚动字幕效果代码
2024-05-22 10:36:09
ASP中一个字符串处理类加强版
2008-11-25 18:07:00
tensorflow 1.X迁移至tensorflow2 的代码写法
2023-07-19 08:30:54
Python 中使用 PyMySQL模块操作数据库的方法
2024-01-26 04:23:11
ThinkPHP中url隐藏入口文件后接收alipay传值的方法
2024-05-03 15:50:25
Linux下MySQL数据库的主从同步复制配置
2024-01-19 12:36:41
parser.add_argument中的action使用
2023-05-18 05:35:57
Django+JS 实现点击头像即可更改头像的方法示例
2021-09-01 19:16:44
![](https://img.aspxhome.com/file/2023/3/117623_0s.png)
JavaScript中的"类" 序言
2008-02-18 13:26:00
python3 pillow模块实现简单验证码
2021-07-04 11:10:44
![](https://img.aspxhome.com/file/2023/5/89145_0s.jpg)
Python利用matplotlib生成图片背景及图例透明的效果
2023-08-22 08:35:18
![](https://img.aspxhome.com/file/2023/1/110271_0s.jpg)
数据库手边系列:SQL Server数据表信息
2009-05-24 18:26:00
Python单链表原理与实现方法详解
2023-05-21 00:58:37
深入理解Python中range和xrange的区别
2023-06-22 06:10:09
MySQL transaction事务安全示例讲解
2024-01-25 17:47:38