Dirty_Fox
Dirty_Fox

Reputation: 1751

How to plot data set on different plots

When I run this code, I do have one plot printing my two data sets a and b. I would like them to be displayed on two separate plots. Thanks in advance

import matplotlib.pyplot as plt

a = range(0,10)
b= range(2,12)

plt.plot(a)
plt.plot(b)

Upvotes: 1

Views: 66

Answers (2)

Andy
Andy

Reputation: 50560

The tutorial shows how to do this. You need to utilize the show() method after each plot.

plt.plot(a)
plt.show()
plt.plot(b)
plt.show()

Alternatively, you can show both at the same time utilizing subplots:

plt.subplot(2, 1, 1)
plt.plot(a)

plt.subplot(2, 1, 2)
plt.plot(b)

plt.show()

This creates the following plot:

Subplots

Upvotes: 1

Paul Pichaureau
Paul Pichaureau

Reputation: 173

You can use the show() method :

import matplotlib.pyplot as plt

a = range(0,10)
b= range(2,12)

plt.plot(a)
plt.show()

plt.plot(b)
plt.show()

Upvotes: 1

Related Questions