脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python matplotlib绘图,修改坐标轴刻度为文字的实例

python matplotlib绘图,修改坐标轴刻度为文字的实例

2021-02-25 00:10大唐乾元 Python

今天小编就为大家分享一篇python matplotlib绘图,修改坐标轴刻度为文字的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

工作中偶尔需要做客流分析,用pyplot 库绘图。一般情况下, x 轴刻度默认显示为数字。

例如:

python matplotlib绘图,修改坐标轴刻度为文字的实例

我希望x 轴刻度显示为星期日期。

查询pyplot 文档, 发现了 xtick() 函数可以修改刻度。

python matplotlib绘图,修改坐标轴刻度为文字的实例

代码如下:

?
1
2
3
4
5
6
7
8
import matplotlib.pyplot as plt
import numpy as np
#val_ls = [np.random.randint(100) + i*20 for i in range(7)]
scale_ls = range(7)
index_ls = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun']
plt.bar(scale_ls, val_ls)
#_ = plt.xticks(scale_ls,index_ls) ## 可以设置坐标字
plt.title('Average customer flows Number by Weekdays')

以上这篇python matplotlib绘图,修改坐标轴刻度为文字的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/u012593888/article/details/78605684

延伸 · 阅读

精彩推荐