You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code is taken in part from the contour demo of the matplotlib documentation. I am using contourf instead of simple contour. The contour plot is shown just as I want it to be within the matplotlib figure window.
As soon as it comes to saving I am not content with the result. A PNG save looks perfect, but I do not have any levels, as png si no vector format. When saving to PDF of SVG format I have levels, BUT there are thin light borders around the levels. At first I thought they are caused, because every level is getting a stroke around. When opening the SVG file with inkscape to drop those strokes, I found out, that actually the levels are saved just a bit to small or a bit too large respectively... you hardly note them, when you zoom in, but by zooming out they get quite prominent. I suppose they are due to the fact, that the values of the levels are saved with low precision!? Is it possible to get rid of theese borders by some command?
I am aware that these borders will not make a difference in most applicative contexts. Unfortunately where I am using them the do not simply look ugly, but really disturb the quality of the depicted results...
import matplotlib
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
matplotlib.rcParams['xtick.direction'] = 'out'
matplotlib.rcParams['ytick.direction'] = 'out'
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = 10.0 * (Z2 - Z1)
plt.ion()
plt.figure()
CS = plt.contourf(X, Y, Z, colors=[[0,0,0.5],[0,0,0.2]])
plt.title('Saved as PNG')
plt.savefig('image1.png')
plt.title('Saved as SVG')
plt.savefig('image1.svg')
The text was updated successfully, but these errors were encountered:
This is a limitation of the vector backends. When rendering 2 surfaces next to each other without overlap round off errors will produce gaps between them. See for instance #1188
As a workaround you can add an edge with the same colour around the patches
The following works for me:
plt.figure()
CS = plt.contourf(X, Y, Z, colors=[[0,0,0.5],[0,0,0.2]])
for a in CS.collections:
a.set_edgecolor('face')
plt.title('Saved as PNG')
plt.savefig('image1.png')
plt.title('Saved as SVG')
plt.savefig('image1.svg')
However note that this would produce similar ugly overlaps if you use it on a semi transparent surface (alpha < 1) due to the overlaps. This is why it is not on by default.
tacaswell
modified the milestones:
next point release,
proposed next point releaseJul 11, 2015
tacaswell
modified the milestones:
2.1 (next point release),
2.2 (next next feature release)Oct 3, 2017
The following code is taken in part from the contour demo of the matplotlib documentation. I am using contourf instead of simple contour. The contour plot is shown just as I want it to be within the matplotlib figure window.
As soon as it comes to saving I am not content with the result. A PNG save looks perfect, but I do not have any levels, as png si no vector format. When saving to PDF of SVG format I have levels, BUT there are thin light borders around the levels. At first I thought they are caused, because every level is getting a stroke around. When opening the SVG file with inkscape to drop those strokes, I found out, that actually the levels are saved just a bit to small or a bit too large respectively... you hardly note them, when you zoom in, but by zooming out they get quite prominent. I suppose they are due to the fact, that the values of the levels are saved with low precision!? Is it possible to get rid of theese borders by some command?
I am aware that these borders will not make a difference in most applicative contexts. Unfortunately where I am using them the do not simply look ugly, but really disturb the quality of the depicted results...
The text was updated successfully, but these errors were encountered: