Skip to content Skip to sidebar Skip to footer

Matplotlib: Scale Axis By Multiplying With A Constant

Is there a quick way to scale axis in matplotlib? Say I want to plot import matplotlib.pyplot as plt c= [10,20 ,30 , 40] plt.plot(c) it will plot How can I scale x-axis quickly,

Solution 1:

Use a numpy.array instead of a list,

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))`

This gives:

>>>print x
array([ 0,  5, 10, 15])

Post a Comment for "Matplotlib: Scale Axis By Multiplying With A Constant"