Skip to content

Spyder-6 advice for Matplotlib users #1590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
stonebig opened this issue May 9, 2025 · 0 comments
Open

Spyder-6 advice for Matplotlib users #1590

stonebig opened this issue May 9, 2025 · 0 comments

Comments

@stonebig
Copy link
Contributor

stonebig commented May 9, 2025

this line at the beginning of your matplotlib program may avoid issues if it runs in the console:

import matplotlib_inline; matplotlib_inline.backend_inline.set_matplotlib_formats('png', 'jpeg');

it's really a no brainer solution:

default run, with inline images, doesn't fail
running it in external console produces the Qt drawing

full example:

import matplotlib_inline; matplotlib_inline.backend_inline.set_matplotlib_formats('png', 'jpeg');

import matplotlib.pyplot as plt
import numpy as np

t = np.linspace(-10, 10, 100)
sig = 1 / (1 + np.exp(-t))

fig, ax = plt.subplots()
ax.axhline(y=0, color="black", linestyle="--")
ax.axhline(y=0.5, color="black", linestyle=":")
ax.axhline(y=1.0, color="black", linestyle="--")
ax.axvline(color="grey")
ax.axline((0, 0.5), slope=0.25, color="black", linestyle=(0, (5, 5)))
ax.plot(t, sig, linewidth=2, label=r"$\sigma(t) = \frac{1}{1 + e^{-t}}$")
ax.set(xlim=(-10, 10), xlabel="t")
ax.legend(fontsize=14)
plt.show()

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant