Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
smroux opened this issue Mar 31, 2017 · 1 comment
Closed

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

smroux opened this issue Mar 31, 2017 · 1 comment

Comments

@smroux
Copy link

smroux commented Mar 31, 2017

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

@phobson
Copy link
Member

phobson commented Mar 31, 2017

See #7293. This was fixed by #8297

@phobson phobson added this to the unassigned milestone Mar 31, 2017
@phobson phobson closed this as completed Mar 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants