Matplotlib figure only shows after second file run

426 Views Asked by At

I am doing some basic plotting routine (as below), and after the first file run I will only get <Figure size 640x460 with 1 Axes> appearing in the output area. And then on the second run of the code, the figure will actually be plotted. Ideally it would plot on the first run, as later I want to test some matplotlib style editting.

import matplotlib.pyplot as plt
import numpy as np
data = np.arange(20)
plt.plot(data  , label='1')
plt.plot(data+2, label='2')
plt.plot(data+4, label='3')
plt.plot(data+6, label='4')
plt.plot(data+8, label='5')
plt.legend()
plt.xlabel('X label')
plt.ylabel('Y label')
plt.show()

I'm using Python 3.6 in Hydrogen (Atom)

1

There are 1 best solutions below

0
On BEST ANSWER
import matplotlib
matplotlib.use('Qt5Agg')

Solves the issue and plots first run (not sure why exactly)