在numpy图中更改轴比例 [英] Changing the axis scale in numpy plot

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

问题描述

我正在基于一个numpy数组绘制图:

I am drawing a plot based on a numpy array:

A = np.array([[4,5,6],[2,3,6]])

使用plt.plot(A)可以正常工作,并基于6个元组绘制:(0,4),(1,5),(2,6),(0,2)等.

with plt.plot(A) it works fine and draws based on 6 tuples: (0,4), (1,5), (2,6), (0,2) etc.

我想缩放x轴.单位应除以120.所以我要绘制:

I want to scale the x-axis though. The units should be divided by 120. So I want to plot:

(0,4), (1/120,5), (2/120, 6), etc. 

有没有简单的方法可以做到这一点,而无需遍历数组并手动将元组供入图?

Is there any easy way to do it, without looping through the array and manually feeding the tuples to the plot?

推荐答案

指定x轴

scaling_factor = 120.
x = np.arange(A.shape[0])/scaling_factor
plt.plot(x, A)

这篇关于在numpy图中更改轴比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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