Matplotlib Basic: Plot several lines with different format styles in one command using arrays
Matplotlib Basic: Exercise-11 with Solution
Write a Python program to plot several lines with different format styles in one command using arrays.
Sample Solution:
Python Code:
import numpy as np
import matplotlib.pyplot as plt
# Sampled time at 200ms intervals
t = np.arange(0., 5., 0.2)
# green dashes, blue squares and red triangles
plt.plot(t, t, 'g--', t, t**2, 'bs', t, t**3, 'r^')
plt.show()
Sample Output:
Python Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Python program to plot quantities which have an x and y position.
Next: Write a Python program to create multiple types of charts (a simple curve and plot some quantities) on a single set of axes.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics