Skip to content
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

No figure shows, no error #6138

Closed
Yefee opened this issue Mar 10, 2016 · 1 comment
Closed

No figure shows, no error #6138

Yefee opened this issue Mar 10, 2016 · 1 comment

Comments

@Yefee
Copy link

Yefee commented Mar 10, 2016

matplotlib version 1.5.1; Py 2.7.11; OSX

The code below can run smoothly without any errors, but it returns no figure when I run it as a script.
If I run it in ipython command, it's fine.
Wired!!
For other script, my python is also fine.
No ideas.

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import matplotlib as mpl

def colorMapper(data):
    #_this helper function returns mapper that will normalize
    #_the colors in your dataset for plotting

    minima = min(data)
    maxima = max(data)
    norm = mpl.colors.Normalize(vmin = minima,
                                vmax = maxima,
                                clip = True)
    mapper = mpl.cm.ScalarMappable(norm = norm)
    return norm, mapper


fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

xs = [1, 1, 1, 1, 1, 1, 1, 1]
ys = [1, 1, 1, 1, 2, 2, 2, 2]
zs = [1, 2, 3, 4, 1, 2, 3, 4]
data = [1, 2, 3, 4, 1, 2, 3, 4]

norm, mapper = colorMapper(data)

for x, y, z, dat in zip(xs, ys, zs, data):
    ax.scatter(x, y, z, color = mapper.to_rgba(dat),s = dat * 10)

plt.savefig('foo.png')
fig.show()
@tacaswell
Copy link
Member

Use plt.show instead of fig.show(). plt.show blocks and runs the GUI event loop, fig.show does not.

Compare

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot(range(3))
print('done creating artists')
# ## Switch which of these are commented out
plt.show()
# fig.show()
print('done showing')

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

2 participants