有没有一种在matplotlib中缩放轴的快速方法?
说我想画
import matplotlib.pyplot as plt c= [10,20 ,30 , 40] plt.plot(c)
它将绘制
如何快速缩放x轴,比如将每个值乘以5?一种方法是为x轴创建一个数组:
x = [i*5 for i in range(len(c))] plt.plot(x,c)
我想知道是否有更短的方法可以做到这一点,而不创建x轴列表,比如像plt.plot(index(c)* 5,c)
使用numpy.array而不是列表,
c = np.array([10, 20, 30 ,40]) # or `c = np.arange(10, 50, 10)` plt.plot(c) x = 5*np.arange(c.size) # same as `5*np.arange(len(c))`
这给出了:
>>> print x array([ 0, 5, 10, 15])
1 回答
使用numpy.array而不是列表,
这给出了: