2013-01-03 7 views
11

In Pythons matplotlib.fill_between wird das folgende minimale Arbeitsbeispiel unten korrekt auf den Bildschirm gezeichnet und auf die .png. In dem resultierenden .pdf sind jedoch die Kantenlinien noch gezeichnet. Wie kann ich das beheben?Warum zeichnet matplotlib fill_between Zeichenkanten nur in PDFs auf?

from numpy import * 
import pylab as plt 

# Sample data 
X = linspace(0,2*pi,1000) 
Y0 = sin(X) 
Y1 = sin(X+.2) 
Y2 = sin(X+.4) 

# fill_kwargs (what am I missing?) 
fbk = {'lw':0.0, 'edgecolor':None} 

ax = plt.subplot(111) 
ax.fill_between(X, 0, Y0 , facecolor = 'b', **fbk) 
ax.fill_between(X, Y0, Y1, facecolor = 'g', **fbk) 
ax.fill_between(X, Y1, Y2, facecolor = 'r', **fbk) 
plt.xlim(pi-.8,pi+.5) 
plt.ylim(-.5,.5) 

plt.savefig('fA.png') # No edge lines 
plt.savefig('fA.pdf') # Edge lines! 

PNG Ergebnis

enter image description here

PDF Ergebnis

enter image description here

Während es trivial scheint, es extrem problematisch wird, wenn Sie 200 fill_between Plots stapeln, alles, was Sie sehen ist eine hässliche Unordnung von Schwarz!

Antwort

10

Es ist nicht perfekt, aber ich habe eine Lösung gefunden (und wird eine bessere akzeptieren, wenn es dazu kommt). Apparently Nachsatz könnte schuld sein:

... note that interpreting a linewidth of zero as a 1 pixel wide line is what PostScript does. So the only way to get a true zero width for PostScript output is to fill the polygon without stroking it.

Die Lösung ist die edgecolor die gleiche wie die facecolor zu machen. Dies funktioniert, aber wenn die FaceColor eine Transparenz hat, scheint die EdgeColor nicht denselben Transparenzwert zu erhalten.

1

Es ist nicht schön überhaupt, aber wenn man es auf None gesetzt ist, wird es diesen Fehler werfen:

Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/matplotlib/artist.py", line 59, >in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/usr/local/lib/python2.7/site-packages/matplotlib/figure.py", line 1085, >in draw func(*args) File "/usr/local/lib/python2.7/site-packages/matplotlib/artist.py", line 59, > in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/usr/local/lib/python2.7/site-packages/matplotlib/axes/_base.py", line > 2110, in draw a.draw(renderer) File "/usr/local/lib/python2.7/site-packages/matplotlib/artist.py", line 59, > in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/usr/local/lib/python2.7/site-packages/matplotlib/lines.py", line 694, >in draw gc.set_linewidth(self._linewidth) TypeError: a float is required

und weiterhin ohne die Linie zu machen. Gestapelte Violinplots funktionieren jetzt mit Seaborn!

mit 0,0 Linienbreite:

with 0.0 linewidth

mit None:

Using None

Verwandte Themen