Skip to content

Data points not rendered for figures saved in vector formats #8412

@smroux

Description

@smroux

Bug report

Bug summary

Matplotlib does not render a data point when saving a figure in any vector graphics format when the individual data point is straddled by nan values.
The images are plotted correctly for any raster format or when using show.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

x_vals = np.arange(1, 9)
y_vals = np.array([2, 4, 6, np.nan, 10, np.nan, 14, 16])
plt.plot(x_vals, y_vals, '.')
plt.axis([0, 9, 0, 18])
plt.grid()

plt.title("Figure 1")
plt.savefig('figure1.png')

plt.title("Figure 2")
plt.savefig('figure2.pdf')

Actual outcome

Below is the figure saved in pdf format.

figure2.pdf

Expected outcome

Below is the same figure saved in png format or generated by show

figure1

The vector format produced the expected outcome in matplotlib 1.5 using qt4agg.
Strangely enough, the expected outcome can also be produced by doing the following:

  • Masking the input array:
mask =  ~np.isnan(y_vals)
plt.plot(x_vals[mask], y_vals[mask], '.')
  • Using scatter instead of plot
  • Having data points in contiguous groups of 2 or more between nan values
y_vals = np.array([2, 4, np.nan, 8, 10, np.nan, 14, 16])

My assumption is that plot is trying to connect the dots, is unable to do so and so ignores the data point.

Matplotlib version
python 3.5.2
matplotlib 2.0.0
numpy 1.11.1
pyqt 5.6.0
installed on Ubuntu 16.04 via anaconda 3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions