Skip to content

Instantly share code, notes, and snippets.

@tenomoto
Created November 22, 2017 07:41
Show Gist options
  • Save tenomoto/3383f21090e6384e31257904835fb1ad to your computer and use it in GitHub Desktop.
Save tenomoto/3383f21090e6384e31257904835fb1ad to your computer and use it in GitHub Desktop.
Mayavi transparent background
# https://stackoverflow.com/questions/23703417/can-mayavi-render-a-figure-scene-with-a-transparent-background
import numpy as np
from mayavi import mlab
import matplotlib.pyplot as plt
d = 3
n = 100
x = np.arange(-d, d, 2 * d / n)
y = np.arange(-d, d, 2 * d / n)
X, Y = np.meshgrid(x, y)
Z = np.sin(X) ** 2 * np.cos(X + Y) + np.cos(Y) ** 2 * np.sin(X - Y) + 3
mlab.figure(size=(1024,768))
mlab.mesh(X, Y, Z, colormap='copper', opacity=0.6)
#mlab.show()
imgmap = mlab.screenshot(mode='rgba', antialiased=True)
plt.axis('off')
plt.imsave(arr=imgmap, fname='rbf_concept_3d.png')
mlab.savefig('foo.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment