Skip to content

plt.show() strong discrepancy to plt.savefig() PNG, PDF & SVG (which are all 'identical') #19491

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

Closed
rengel8 opened this issue Feb 10, 2021 · 1 comment

Comments

@rengel8
Copy link

rengel8 commented Feb 10, 2021

Bug report

Bug summary

The saved figures of a scatter plot are rendered/interpreted completely different from showing them. This is consistent and might be related to #18871 and/or #8847. Is there a way to circumvent this and to get closer to the desired plot from 'show()' whilst saving to a file?

Code for reproduction

import matplotlib.pyplot as plt         # for my tests version 3.3.2
import numpy as np

# Creating dataset
np.random.seed(42)
x = np.random.random_sample(size=10000)
y = np.random.random_sample(size=10000)
z = np.random.random_sample(size=10000)

# Creating figure
fig = plt.figure(figsize=(16, 9))
ax = plt.axes(projection="3d")

# Add x, y gridlines
ax.grid(b=True, color='grey', linestyle='-.', linewidth=0.3, alpha=0.2)

# Creating color map
# https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html
my_cmap = plt.get_cmap('brg')

# Creating plot
sctt = ax.scatter3D(x, y, z, alpha=0.8, c=z, cmap=my_cmap, marker='o')

plt.title("3D-Scatter")
ax.set_xlabel('x label', fontweight='bold')
ax.set_ylabel('y label', fontweight='bold')
ax.set_zlabel('z label', fontweight='bold')
fig.colorbar(sctt, ax=ax, shrink=0.5, aspect=5)

# show plot
plt.show()
# plt.savefig('fig_savefig.png')
plt.close()

Actual outcome
fig_savefig

Expected outcome
fig_show

Matplotlib version

  • Operating system: Win10
  • Matplotlib version (import matplotlib; print(matplotlib.__version__)): 3.3.2
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg
  • Python version: 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)]
  • Jupyter version (if applicable):
  • Other libraries:
@QuLogic
Copy link
Member

QuLogic commented Feb 10, 2021

This was fixed by #18885; please update to 3.3.3+.

@QuLogic QuLogic closed this as completed Feb 10, 2021
@QuLogic QuLogic added this to the v3.3.3 milestone Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants