matplotlib 有没有快速缩放轴的方法?
说我想要情节
import matplotlib.pyplot as plt
c= [10,20 ,30 , 40]
plt.plot(c)
Run Code Online (Sandbox Code Playgroud)
它会绘制
如何快速缩放x 轴,例如将每个值乘以5?一种方法是为x轴创建一个数组:
x = [i*5 for i in range(len(c))]
plt.plot(x,c)
Run Code Online (Sandbox Code Playgroud)
我想知道是否有更短的方法来做到这一点,而不创建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))`
Run Code Online (Sandbox Code Playgroud)
这给出:
>>> print x
array([ 0, 5, 10, 15])
Run Code Online (Sandbox Code Playgroud)