Inconsistent behavior in plt.hist

I get inconsistent behavior when plotting multiple sets of data with plt.hist. Here's a quick example:

import numpy as np
import matplotlib.pyplot as plt
x = np.random.randn(10)
y = np.random.randn(9)
plt.hist([x, y])

The above code plots two sets of histograms, as expected. My data sets have different lengths, but by coincidence, I had two data sets with the same length. When you call hist on data sets with the same length

plt.hist([x[:-1], y])

then hist actually transposes the data; for the above, you get 9 sets of data instead of two.

Below is a patch that fixes the issue, but unfortunately, it'll probably break other peoples' code; in fact, it breaks the example code ( I'm not sure what's worse: dealing with the inconsistency or breaking a lot of code. But if there's a time to break code, MPL 1.0 might be it :slight_smile:


Index: lib/matplotlib/


--- lib/matplotlib/ (revision 8187)
+++ lib/matplotlib/ (working copy)
@@ -7122,7 +7122,7 @@

             # make sure a copy is created: don't use asarray
- x = np.transpose(np.array(x))
+ x = np.array(x)
             if len(x.shape)==1:
                 x.shape = (1,x.shape[0])
             elif len(x.shape)==2 and x.shape[1]<x.shape[0]: