Matplotlib svg save - light borders around outline levels

The following code is taken in part from the outline demo of the matplotlib documentation. I am using contourf instead of a simple outline. The contour plot is shown the same way I want it to be in the matplotlib figure window.

When it comes to saving, I'm not happy with the result. Saving PNG looks perfect, but I don't have any level like png si without vector format. When saving as SVG PDF I have levels BUT there are thin light borders around the levels. At first I thought they were caused because each level is collapsing. Opening the SVG file with inkscape to discard those strokes, I found out that in fact the levels are kept just a little, or too small or too large, respectively ... you hardly notice them when you zoom in, but when you zoom in they become very noticeable. I guess they are due to the fact that the level values ​​are stored with low precision !? Is it possible to get rid of these boundaries by some team?

I know these boundaries won't matter in most application contexts. Unfortunately, where I use them don't just look ugly, but really break the quality of the displayed 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')

      

saved as PNGsaved as SVG

+3
python matplotlib export save svg


source to share


No one has answered this question yet

Check out similar questions:

1015
Save the image to an image file instead of displaying it with Matplotlib
130
Removing space around a saved image in matplotlib
79
Saving Interactive Matplotlib Drawings
13
Matplotlib svg as string, not file
ten
draw border around subplots in matplotlib
2
How to set miterlimit when saving as svg with matplotlib
2
Changing font while saving svg from matplotlib
0
Update outline with colorbar in matplotlib
0
Matplotlib outline with 3 colors
0
How to pgf savefig matplotlib figure with multiple imshow plots as * .svg and not * .png?



All Articles
Loading...
X
Show
Funny
Dev
Pics