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
Dear developers,
when plotting single points surrounded by np.nan values, points are shown in a regular plot, but are omitted when saved via pdf backend. Minimal example:
import numpy as np
import matplotlib.pyplot as plt
a = np.array([1,np.nan,2,np.nan,3,3.5,4])
plt.plot(a, marker='o')
plt.show()
generates a perfect plot with the 5 points shown:
but directly saving it via pdf backend omitts the values isolated by np.nans:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.backends.backend_pdf as pdf
a = np.array([1,np.nan,2,np.nan,3,3.5,4])
fig1 = plt.figure()
sub = fig1.add_subplot(1,1,1)
sub.plot(a,marker='o')
pp1 = pdf.PdfPages('foo.pdf')
fig1.savefig(pp1, format='pdf')
pp1.close()
Same problem encountered (matplotlib 2.0.0) when plotting data from apandas.DataFrame. Filtering out the NaN fixed it, thanks @tacaswell.
Also, scatter doesn't seem to be affected as the correct output is saved without needing to filtering out for the NaNs.
This bug sounds familiar. Didn't we have something like this when we messed
around with the line chopping code originally? Something about handling
chopping on nan segments?
The covert_to_string is a bit of a red herring. in Line2D we draw lines in two passes, the first is the line which goes through convert_to_string (which is correctly simplifying out the nan ponts). The markers are drawn in a second step (well, actually 2 steps as we support 2-tone markers, but I digress) with calls to draw_markers. The issue is that in path.iter_segments used in draw_markers the clipping logic removes any multiple 'moves' in a row (and only keeps the last one). We need to see those points to draw the markers.
We don't see this problem in Agg because it's draw_markers does not have the clipper in it's path proccesing pipeline. Not sure yet if this is an oversight or we are relying on the Agg rasterer to do the clipping for us.
Activity
anntzer commentedon Oct 17, 2016
Confirmed on 2.0b4. This affects (at least?) all backends that rely on
convert_to_string(defined insrc/_path.h): pdf, ps and svg.tacaswell commentedon Feb 7, 2017
This is a pretty nasty bug and a regression from 1.5.
Suspect we just need to chop the paths up better?
gcalmettes commentedon Feb 7, 2017
Same problem encountered (matplotlib 2.0.0) when plotting data from a
pandas.DataFrame. Filtering out theNaNfixed it, thanks @tacaswell.Also,
scatterdoesn't seem to be affected as the correct output is saved without needing to filtering out for theNaNs.WeatherGod commentedon Feb 7, 2017
tacaswell commentedon Mar 14, 2017
The
covert_to_stringis a bit of a red herring. inLine2Dwe draw lines in two passes, the first is the line which goes throughconvert_to_string(which is correctly simplifying out the nan ponts). The markers are drawn in a second step (well, actually 2 steps as we support 2-tone markers, but I digress) with calls todraw_markers. The issue is that inpath.iter_segmentsused indraw_markersthe clipping logic removes any multiple 'moves' in a row (and only keeps the last one). We need to see those points to draw the markers.We don't see this problem in Agg because it's
draw_markersdoes not have the clipper in it's path proccesing pipeline. Not sure yet if this is an oversight or we are relying on the Agg rasterer to do the clipping for us.FIX: do not skip isolated points in vector outputs
FIX: do not skip isolated points in vector outputs
FIX: do not skip isolated points in vector outputs
NelleV commentedon Mar 20, 2017
Fixed in #8297