通过matplotlib中的一个因子更改绘图比例 [英] Changing plot scale by a factor in matplotlib

查看:106
本文介绍了通过matplotlib中的一个因子更改绘图比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用python创建一个情节.有没有一种方法可以按比例缩放轴? yscalexscale命令仅允许我关闭对数刻度.

I am creating a plot in python. Is there a way to re-scale the axis by a factor? The yscale and xscale commands only allow me to turn log scale off.


例如.如果我有一个图,其中x比例从1 nm变为50 nm,则x比例将在1x10 ^(-9)到50x10 ^(-9)的范围内,并且我希望它从1变为50. ,我希望绘图函数将放置在绘图上的x值除以10 ^(-9)


For example. If I have a plot where the x scales goes from 1 nm to 50 nm, the x scale will range from 1x10^(-9) to 50x10^(-9) and I want it to change from 1 to 50. Thus, I want the plot function to divide the x values placed on the plot by 10^(-9)

推荐答案

为什么不更改刻度,而不更改单位?制作x值的单独数组X,其单位为nm.这样,当您绘制数据时,它已经是正确的格式!只需确保添加xlabel来指示单位(无论如何总是都应完成).

Instead of changing the ticks, why not change the units instead? Make a separate array X of x-values whose units are in nm. This way, when you plot the data it is already in the correct format! Just make sure you add a xlabel to indicate the units (which should always be done anyways).

from pylab import *

# Generate random test data in your range
N = 200
epsilon = 10**(-9.0)
X = epsilon*(50*random(N) + 1)
Y = random(N)

# X2 now has the "units" of nanometers by scaling X
X2 = (1/epsilon) * X

subplot(121)
scatter(X,Y)
xlim(epsilon,50*epsilon)
xlabel("meters")

subplot(122)
scatter(X2,Y)
xlim(1, 50)
xlabel("nanometers")

show()

这篇关于通过matplotlib中的一个因子更改绘图比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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