Skip to content

Allow rasterization for 3D plots #10013

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

Conversation

ImportanceOfBeingErnest
Copy link
Member

3D plots do not allow for rasterization. It seems this is only due to the missing decorator (@allow_rasterization) of the respecive draw methods.

In this patch I'm adding the decorator to all draw methods in art3d.py to see what happens.

This would allow to rasterize 3D objects, like

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

fig = plt.figure()
ax = fig.gca(projection=Axes3D.name)

x = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(x, x)
Z = np.sin(np.sqrt(X**2 + Y**2))

surf = ax.plot_surface(X, Y, Z, cmap="coolwarm",
                       linewidth=0, antialiased=True)
surf.set_rasterized(True)

plt.savefig("rasterizedsurface.pdf")
plt.show()

resulting in (screenshot from pdf):

image

3D plots do not allow for rasterization. It seems this is only due to the missing decorator (`@allow_rasterization`) of the respecive `draw` methods. 

In this patch I'm adding the decorator to all draw methods in `art3d.py` to see what happens. 

This would allow to rasterize 3D objects, like

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

fig = plt.figure()
ax = fig.gca(projection=Axes3D.name)

x = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(x, x)
Z = np.sin(np.sqrt(X**2 + Y**2))

surf = ax.plot_surface(X, Y, Z, cmap="coolwarm",
                       linewidth=0, antialiased=True)
surf.set_rasterized(True)

plt.savefig("rasterizedsurface.pdf")
plt.show()
```

resulting in (screenshot from pdf):
@ImportanceOfBeingErnest
Copy link
Member Author

ImportanceOfBeingErnest commented Dec 15, 2017

Of course one would need to do the same with the other files in mplot3d, to also allow the axes to be rasterized.

I do not know how to add another file change to this commit without creating a complete new pull request (and I do not want to spam the PR queue); so maybe someone wants to explain that to me if the general idea of this is well received.

@jklymak
Copy link
Member

jklymak commented Dec 15, 2017

http://matplotlib.org/devdocs/devel/gitwash/index.html

Do you mean if you change another file? You just git commit -a -m "Your message" and then git push origin your-branch, and the PR will be updated. If you want to just have one commit listed then you will need to git rebase. See link above under "Changing History"

@ImportanceOfBeingErnest
Copy link
Member Author

Thanks @jklymak but I have to admit I'm on a totally different level here. I just hit the "New Pull Request" Button on the website to create this PR. I don't even have Git installed currently.

@jklymak
Copy link
Member

jklymak commented Dec 15, 2017

Oh, hmmm, well thats going to be an awkward way to do much sophisticated contribution. If you are up for it check out the rest of the development guide: http://matplotlib.org/devdocs/devel/contributing.html

Its a bit of a pain the first time, and maybe a big pain if you are on Windows, but once you've got it set up its pretty easy.

@phobson
Copy link
Member

phobson commented Dec 15, 2017

@ImportanceOfBeingErnest if you navigate to your fork, then select your branch, any changes you commit through the web interface will be added to the PR.

image

To add an entirely new file, use the UI elements to the right of the page:

image

@anntzer
Copy link
Contributor

anntzer commented Mar 26, 2018

Closed by #10158, thanks for the PR.

@anntzer anntzer closed this Mar 26, 2018
@QuLogic QuLogic added this to the v3.0 milestone Mar 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants