I'm having a baffling issue with saving figures with a specified line alpha in matplotlib. I would really appreciate any input. I found this previous thread but changing the rasterization does not seem to fix the issue.
Here's the minimal example I have of where this issue shows up:
import numpy as np
import matplotlib.pyplot as plt
arr = np.random.randn(10000, 2)
plt.plot(arr[:,0], arr[:,1],alpha=.09, color='black')
plt.savefig('dots_vector.pdf')
plt.show()
In the the display window, it looks like the following (what I want):
However, when I save it as a PDF or PNG, it looks like the following:
Note, I've tried the following setting:
ax.set_rasterized(True)
As that's what the previous thread suggested, but this does not fix the problem.
Bizarrely, when I change the marker type of the line, to the following:
plt.plot(arr[:,0], arr[:,1], 'o', alpha=.09, color='black')
The alpha seems to behave exactly as expected either as a PDF or a PNG, seen here:
Any ideas would be greatly appreciated on how to get the alpha to save properly for the line plot, as I'm pretty stumped.