Python中文
首页
教程
问答
标签
搜索
登录
注册
如何强制Y轴在Matplotlib中仅使用整数?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正在使用matplotlib.pyplot模块绘制直方图,我想知道如何强制y轴标签只显示整数(如0、1、2、3等),而不显示小数(如0、0.5、1、1.5、2)。等等)。</p> <p>我在看指导说明,怀疑答案就在<a href="http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.ylim">matplotlib.pyplot.ylim</a>附近,但到目前为止,我只能找到设置最小和最大y轴值的东西。</p> <pre><code>def doMakeChart(item, x): if len(x)==1: return filename = "C:\Users\me\maxbyte3\charts\\" bins=logspace(0.1, 10, 100) plt.hist(x, bins=bins, facecolor='green', alpha=0.75) plt.gca().set_xscale("log") plt.xlabel('Size (Bytes)') plt.ylabel('Count') plt.suptitle(r'Normal Distribution for Set of Files') plt.title('Reference PUID: %s' % item) plt.grid(True) plt.savefig(filename + item + '.png') plt.clf() </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>这对我有效:</p> <pre><code>import matplotlib.pyplot as plt plt.hist(... # make the y ticks integers, not floats yint = [] locs, labels = plt.yticks() for each in locs: yint.append(int(each)) plt.yticks(yint) </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何将python输出重定向到python控制台和Windows中的文本文件
9 回答
如何将Python运行时嵌入运行在Windows上的R包中
1 回答
如何将python进程作为另一个Windows us运行
4 回答
如何将Python进程的输出用Python管道传输?
2 回答
如何将Python进程的输出重定向到Rust进程?
10 回答
如何将python连接到Azure云并创建Azure数据工厂
4 回答
如何将Python连接到Db2
4 回答
如何将python连接到IBMDB2?
2 回答
如何将Python连接到microsoftaccess数据库文件?
4 回答
如何将python连接到MySQL服务器
10 回答
如何将Python连接到Node.js?
2 回答
如何将python连接到Oracle Application Express
1 回答
如何将Python连接到PostgreSQL
8 回答
如何将Python连接到Postgres服务器?
1 回答
如何将Python连接到SAS Enterprise Guide(EG)服务器
7 回答
如何将Python连接到Spark会话并保持RDDs的Ali
1 回答
如何将python连接到sqlite3并在上填充多行
4 回答
如何将python连接到使用docker运行的cassandra
2 回答
如何将python退格应用于字符串
7 回答
如何将python逻辑应用到tkinter GUI中?这是一个简单的GET请求程序
1 回答