-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
Bug summary
plt.plot()
with None
/ np.nan
row spacers doesn't allow for alpha-d lines to weigh on top of each other; instead, the collective lines all display with the same alpha
value everywhere, regardless of overlap.
(I can of course fall back to the LineCollection
to regain single line + alpha
capabilities, but it would be nice if that weren't necessary.)
Code for reproduction
import matplotlib.pyplot as plt
import numpy as np
dat = np.arange(10).reshape(-1, 2)
fig, axes = plt.subplots(2, 2, figsize=(8, 8))
axes.flatten()[0].plot(dat[:, 0], dat[:, 1], alpha=1.0, c="blue")
axes.flatten()[0].set_title("Full Alpha")
axes.flatten()[1].plot(dat[:, 0], dat[:, 1], alpha=1/10, c="blue")
axes.flatten()[1].set_title("1/10 Alpha")
for i in range(10):
axes.flatten()[2].plot(dat[:, 0], dat[:, 1], alpha=1/10, c="blue")
axes.flatten()[2].set_title("10 Lines of 1/10 Alpha")
temp = np.r_[dat, [[None, None]]]
temp_to_plot = np.row_stack([temp for _ in range(10)])
axes.flatten()[3].plot(temp_to_plot[:, 0], temp_to_plot[:, 1], alpha=1/10, c="blue")
axes.flatten()[3].set_title("Supposed to be\n"
"10 Lines of 1/10 Alpha = Full Alpha")
fig.subplots_adjust(hspace=0.5, wspace=0.5)
fig.set_facecolor("white")
plt.show()
Actual outcome
Expected outcome
The hope was the bottom right line would be full alpha, due to it being 10 identical lines at 1/10 alpha on top of each other, but instead it comes out as 1/10 alpha.
Additional information
The key conditions for replicating here are having multiple lines separated in a single (n, 2)
array by a [None, None]
/ [np.nan, np.nan]
row, and choosing to plot with alpha
< 1.0.
Operating system
Ubuntu
Matplotlib Version
3.5.3
Matplotlib Backend
module://matplotlib_inline.backend_inline
Python version
Python 3.8.13
Jupyter version
6.4.12
Installation
conda