Prev: What is 'matlpotlib'? | Next: Customizing the plot
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
f = np.array([1,2,3,4,5,6,7,8,9,10])
plt.plot(f)
By simply calling 'plot(f)' a graph of the array N values is plotted against the [0,N-1] values in x-axis using the default line style (blue color, continuous line)
Just call plot(x, f) where x is the array with the x-axis values
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
x = np.array([1,2,3,4,5,6,7,8,9,10])/2
f = 2*x
plt.plot(x,f)
# Now the array f = 2*x is plotted against the x values [0.5, 5.0]
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
x = np.array([i for i in range(20)])
f2 = 2*x
plt.plot(x,f2, 'g*')
f3 = 3*x
plt.plot(x,f3, 'r--')
f5 = 5*x
plt.plot(x,f5, 'm^')
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
x = np.linspace(0,10,30)
f1 = x
f2 = 2*x
f3 = 3*x
plt.plot(x, f1, 'k--', x, f2, 'mo', x, f3, 'g.')
For example, the red line below is plotted based on column (x, f) pairs: (3,8), (6, 64) and (9, 512)
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
x = np.array([[1,2,3],[4,5,6],[7,8,9]]) #reshape(3,3)
f = 2**x
print(x)
print(f)
plt.plot(x, f)
. Free learning material
. See full copyright and disclaimer notice