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?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework