Description
Bug summary
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
import matplotlib.pyplot as plt
import numpy as np
x = 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 incorrect
ax2.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.1
ax3.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.
Expected outcome
Additional information
No response
Operating system
No response
Matplotlib Version
3.10.1
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
None