-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
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.
Expected outcome
Below is the same figure saved in png format or generated by show
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 ofplot
- 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