-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Gouraud shading with tripcolor renders incorrectly as SVG in Jupyter notebook #11321
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
Comments
SVG is a vector based format. Does anybody know if SVG supports gouraud
shading in the format specs? If not, then what you have to do is specify
"rasterized=True" in the arguments for tripcolor() sothat the tripcolor is
not saved as a vector but as a bitmap within the SVG file.
…On Tue, May 29, 2018 at 1:05 AM, Avinash Sharma ***@***.***> wrote:
The problem is not specific to "SVG" backend or to Jupyter. Even on saving
the plot in "SVG" format with a different backend, the saved "SVG" has the
same problem.
Try this:
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.tri as mtri
#plt.switch_backend('svg')
plt.switch_backend('nbAgg')
# Mesh
N = 10
x, y = np.linspace(0, 1, N), np.linspace(0, 1, N)
X, Y = np.meshgrid(x, y)
# simple function over the mesh
Z = X**2 + Y**2
# triangulate
tri = mtri.Triangulation(X.ravel(), Y.ravel())
# plot
fig, ax = plt.subplots(1, 2)
# default
ax = fig.add_subplot(1, 2, 1)
ax.tripcolor(tri, Z.ravel(),
cmap=plt.cm.coolwarm)
ax.set_title('default')
ax.axis('equal')
# gouraud
ax = fig.add_subplot(1, 2, 2)
ax.tripcolor(tri, Z.ravel(),
cmap=plt.cm.coolwarm,
shading='gouraud')
ax.set_title('gouraud')
ax.axis('equal')
plt.savefig('output.svg', dpi= 1000)
plt.savefig('output.png', dpi= 1000)
plt.show()
Although the *.show()* output and *png* file have correct shading but the
*svg* file is still incorrect.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#11321 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-FIOwr0E33c9HslbHMd-wzfCMu84ks5t3NcqgaJpZM4UParc>
.
|
It has the right methods, matplotlib/lib/matplotlib/backends/backend_svg.py Lines 664 to 773 in 1966a7a
but claims to not support it
There probably needs to be some git-forensics to sort the history out here. |
The problem is with the SVG backend. Its giving correct output with cario backend. Here's the mplcairo implementation to generate SVG file and it seems to work.
|
@avinashmnit30 Is a diff of the two svg files understandable? |
@tacaswell "Cario backend" is using PNG image within Example:Code for reproduction: https://matplotlib.org/2.0.1/examples/pylab_examples/quadmesh_demo.html |
Is this still an open issue given #11378? |
fwiw cairo (and thus mplcairo) renders this "correctly" as SVG, but does so by rasterizing the entire mesh. |
The current version of svg_backend doesn't work. I think rasterizing the mesh is the only way to achieve Gouraud shading in SVG files at this moment. Because even if triangles get right Gouraud colors, the anti-aliasing issue (#5694) between two adjacent patches would out make the output useless. Something like this: |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
I think this is still valid. |
I recently had an issue with svg format and 'gouraud' shading. |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
What is the way forward here? As far as I've understood, svg does not support gouraud shading unless you rasterize the surface. Minimal idea: Can we check the state upon rendering and issue a warning when gouraud shading is used without rasterization? |
Bug report
Bug summary
When the matplotlib backend is set to 'SVG' in a Jupyter Notebook, it seems that matplotlib does not render 'gouraud' shading correctly.
Code for reproduction
I've uploaded a minimal example of my problem here:
https://nbviewer.jupyter.org/github/CorbinFoucart/FEMexperiment/blob/master/app/mpl_bug.ipynb
Actual outcome
Note the 'gouraud' shading with SVG in the notebook. If I save the output to file and view the output, it is similarly not shaded, which indicates to me that this is not a Jupyter issue, nor a browser issue.
Matplotlib version
print(matplotlib.get_backend())
): module://ipykernel.pylab.backend_inlineI installed matplotlib in a virtual environment with
pip
.The text was updated successfully, but these errors were encountered: