question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spyder is not displaying Matplotlib Plot inline

See original GitHub issue

Problem Description

Not able to display Matplotlib plot inline in Spyder.

What steps reproduce the problem?

Running the follow ing Python program in Spyder:

“”" Spyder Editor

This is a temporary script file. “”"

import matplotlib.pyplot as plt
import numpy as np

plt.switch_backend('QT5Agg')
plt.style.use("ggplot")

t = np.arange(0.0, 2.0, 0.1)
s = np.sin(2 * np.pi * t)
s2 = np.cos(2 * np.pi * t)
plt.plot(t, s, "o-", lw=4.1)
plt.plot(t, s2, "o-", lw=4.1)
plt.xlabel("time (s)")
plt.ylabel("Voltage (mV)")
plt.title("Simple plot $\\frac{\\alpha}{2}$")
plt.grid(True)

plt.savefig("test.png")

plt.show()

What is the expected output? What do you see instead?

I expected to see my plot inline in Spyder, I get the plot in a separate Python window. See below:

Screen Shot 2021-02-09 at 03 40 03 ### Paste Traceback/Error Below (if applicable)
IPython console displayed:
Python 3.8.1 (default, Jan  8 2020, 16:15:59) 
Type "copyright", "credits" or "license" for more information.

IPython 7.20.0 -- An enhanced Interactive Python.

runfile('/Users/user/temp.py', wdir='/Users/user')

Versions

  • Spyder version: 4.2.1
  • Python version: 3.8.5
  • Qt version: 5.9.7
  • PyQt version: 5.9.2
  • Operating System name/version: Mac OS X, Big Sur (11.2)

Dependencies

N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
OrbitalMechaniccommented, Feb 10, 2021

Thank you. Between commenting out plt.switch_backend( ‘QT5Agg’ ), setting Backend to Inline and restarting the kernel did the trick. I appreciate the help from all the contributors to this thread.

Sam Dupree.

On February/10/2021 00:06:59, Carlos Cordoba wrote:

Hey @OrbitalMechanic https://github.com/OrbitalMechanic, thanks for reporting. You’re changing the backend to Qt in this line of the code you posted above:

plt.switch_backend(‘QT5Agg’)

so that’s why you’re not getting inline plots in Spyder. If you comment it, you’ll see your plot in the Plots pane.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spyder-ide/spyder/issues/14723#issuecomment-776445159, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABEO3565ZWWRPAPGMMHKPC3S6IH7HANCNFSM4XKSDWKA.

0reactions
ccordoba12commented, Feb 10, 2021

Hey @OrbitalMechanic, thanks for reporting. You’re changing the backend to Qt in this line of the code you posted above:

plt.switch_backend('QT5Agg')

so that’s why you’re not getting inline plots in Spyder. If you comment it, you’ll see your plot in our Plots pane.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plot inline or a separate window using Matplotlib in Spyder IDE
I know that in Spyder, click Tools, Preferences, Ipython Console, Graphics and under Graphics Backend select “automatic” instead of “inline”.
Read more >
Visualisation and plotting with Matplotlib - wradlib
%matplotlib inline turns on “inline plotting”, where plot graphics will appear in your notebook. This has important implications for interactivity: for inline ......
Read more >
How do I get interactive plots again in Spyder/Ipython ...
To get interactive plots, we need to activate the figure. Using plt.ioff() and plt.ion(), we can perform interactive actions with plot.
Read more >
Interactive figures — Matplotlib 3.6.2 documentation
Creates a new empty Figure or selects an existing figure. pyplot.subplots ... newly created figures and changes to figures are not displayed until....
Read more >
Python – Show plots in new window instead of inline (not ...
Go to Tools > preferences > IPython console > Graphics > Graphics backend > Backend: Automatic After this don't forget to restart the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found