You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Unexpected behavior of the line style specifiers in the histogram method #29857
There is a strange change on the behavior of the line style specifiers of the hist method in matplotlib when moving from version 3.9.0 to 3.10.1. It seems like the linestyle and ls arguments are behaving differently. In addition, it is no longer possible to specify a customized line style for histograms via a tuple ls=(0, (1, 10)). This is not the case for the plot method.
In matplotlib 3.9.0:
In matplotlib 3.10.1:
Using the linestyle argument with (0, (1, 10)) as a value leads to the following error
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
Note that when using ls there is no error, but the result is not what we would expect.
Code for reproduction
importmatplotlib.pyplotaspltimportnumpyasnpx=np.random.normal(0, 1, 10_000)
fig, ((ax0, ax1), (ax2, ax3)) =plt.subplots(2, 2, figsize=(8, 8))
ax0.plot(x, x, ls=(0, (1, 10)), lw=2)
ax0.set_title("scatter plot (ls)")
ax1.plot(x, x, linestyle=(0, (1, 10)), lw=2)
ax1.set_title("scatter plot (linestyle)")
# this does not display any error, but the histogram is incorrectax2.hist(x, bins=10, range=(-5, +5), ls=(0, (1, 10)), histtype="step", lw=2)
ax2.set_title("hist (ls)")
# this gives an error in 3.10.1ax3.hist(x, bins=10, range=(-5, +5), linestyle=(0, (1, 10)), histtype="step", lw=2)
ax3.set_title("hist (linestyle)")
plt.show()
Actual outcome
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
Activity
rcomer commentedon Apr 2, 2025
Thanks for the report @mramospe. The difference between ls and linestyle was fixed by #29552 and the
ValueErrorwas fixed by #29719.mramospe commentedon Apr 2, 2025
Thanks a lot @rcomer. I apologize since I missed the closed issue. Looking forward to the new release.