w3resource

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:

Matplotlib Basic: Plot several lines with different format styles in one command using arrays

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?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/graphics/matplotlib/basic/matplotlib-basic-exercise-11.php