Skip to content

Isolated points missing in pdf #7293

Closed
Closed

Description

@peterchenchenchen

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:

foo1

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()

like so:

foo2

I would be glad for any help.

System:
Ubuntu 14.02
Python 2.7.6
Numpy 1.11.2
Matplotlib 1.5.3

Activity

  1. anntzer commented on Oct 17, 2016

    @anntzer
    Contributor

    Confirmed on 2.0b4. This affects (at least?) all backends that rely on convert_to_string (defined in src/_path.h): pdf, ps and svg.

  2. added this to the milestone on Oct 19, 2016
  3. added
    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
    on Feb 7, 2017
  4. tacaswell commented on Feb 7, 2017

    @tacaswell
    Member

    This is a pretty nasty bug and a regression from 1.5.

    Suspect we just need to chop the paths up better?

  5. gcalmettes commented on Feb 7, 2017

    @gcalmettes

    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.

  6. WeatherGod commented on Feb 7, 2017

    @WeatherGod
    Member
  7. self-assigned this
    on Mar 13, 2017
  8. tacaswell commented on Mar 14, 2017

    @tacaswell
    Member

    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.

  9. added 3 commits that reference this issue on Mar 14, 2017
    bb0d1a9
    27d4596
    5f54543
  10. NelleV commented on Mar 20, 2017

    @NelleV
    Member

    Fixed in #8297

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions