如何在matplotlib中设置轴的单位长度? [英] How to set the unit length of axis in matplotlib?

查看:49
本文介绍了如何在matplotlib中设置轴的单位长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如 x = [1~180,000]当我在x轴上绘制它时,它显示:1,20,000,40,000,... 180,000这些0真的很烦

For example x = [1~180,000] When I plot it, in x axis, it shows: 1, 20,000, 40,000, ... 180,000 these 0s are really annoying

如何将 x 轴的单位长度更改为 1000,使其显示:1, 20, 40, ... 180并在某处显示其单位为 1000.

How can I change the unit length of x axis to 1000, so that it show:1, 20, 40, ... 180 and also show that somewhere its unit is in 1000.

我知道我自己可以进行线性变换.但是在 matplotlib 中不是有这样的函数吗?

I know I can do a linear transformation myself. But isn't there a function doing that in matplotlib?

推荐答案

如果您要制作出版物质量数据,则希望对坐标轴标签进行精细控制.一种方法是提取标签文本并应用您自己的自定义格式:

If you are aiming on making publication quality figures, you'll want to a fine control over the axes labels. One way to do this is to extract the label text and apply your own custom formatting:

import pylab as plt
import numpy as np

# Create some random data over a large interval
N = 200
X = np.random.random(N) * 10 ** 6
Y = np.sqrt(X)

# Draw the figure to get the current axes text
fig, ax = plt.subplots()
plt.scatter(X,Y)
ax.axis('tight')
plt.draw()

# Edit the text to your liking
label_text   = [r"$%i \cdot 10^4$" % int(loc/10**4) for loc in plt.xticks()[0]]
ax.set_xticklabels(label_text)

# Show the figure
plt.show()

这篇关于如何在matplotlib中设置轴的单位长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆