How to create more than one graph in matplotlib?

Asked

Viewed 3,028 times

4

I need to create graphs of histograms in python with lists resulting from transformations. My doubt is that whenever I run the program, the next image only appears after I close the previous one.

transformacaoEscala(U,V,n,a,b)
plt.figure(figsize=(10,6), dpi=80)
histogram(V,12)
plt.show()
somaVetores(U1,U2,U,n)
plt.figure(figsize=(10,6), dpi=80)
histogram(U,10)
plt.show()

As a tool to create images that appear separately?

  • Your doubt is how to put the histograms in a single figure (image)?

1 answer

1

You must use the command subplot for each graph, an example of its use may be this:

import numpy as np
import matplotlib.pyplot as plt

def f(t):
    return np.exp(-t) * np.cos(2*np.pi*t)

t1 = np.arange(0.0, 5.0, 0.1)
t2 = np.arange(0.0, 5.0, 0.02)

plt.figure(1)
plt.subplot(211)
plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k')

plt.subplot(212)
plt.plot(t2, np.cos(2*np.pi*t2), 'r--')
plt.show()

As presented here. Since the first digit corresponds to the number of lines of graphs, the 2nd the number of columns and the 3rd corresponds to the number of each graph.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.