# Flip the axes in the Histogram Plot

I have a matrix and I would like to plot the square of its element.

n = 10;
H = RandomReal[{0, 1}, {n, n}];;
MatrixForm@H
H1=H*H;
Histogram[H1[[1]]]


First row is H1[[1]]

{0.977106, 0.720555, 0.230498, 0.432439, 0.180738, 0.0134593, \
0.592225, 0.0321264, 0.587188, 0.333721}


I got this, I wanted these values to be along $y$ and there position in columns to be along $x$. I saw this How can I transpose $x$ and $y$ axis on a Plot?. But this unnecessary complicated to just switch them and also it is for a function and I have list data. Is there any simple way to do that.

NOTE

Values along $X$ $->$ Like probabilities and $Y$ $->$ Locations (like 1st site, 2nd site, and so on). Want to see the plot otherway.

• @Kuba I would like to maintain the plot on top of X-axes only values to be switched. Even values also get switched, so no change as such. – L.K. Oct 6 '16 at 9:03
• Your question still isn't clear. It sounds like maybe you just want a default-style histogram of your data sorted the other way? In that case use Transpose. – dionys Oct 6 '16 at 9:36
• @dionys Please tell me if anything is unclear, I will try to clear it(but editing my question). Transpose will not work.I have tried. See the edited, if it works – L.K. Oct 6 '16 at 9:41

Module[{n = 10, data, h1}, data = RandomReal[{0, 1}, {n, n}];
Print@data[[1]];
h1 = Part[data^2, 1]; Print@h1;
Print@Histogram[h1, PlotLabel -> "default histogram view"];
RectangleChart[Transpose[{Array[1 &, n], h1}],
PlotLabel -> "rectangle chart view",
ChartLabels -> ToString /@ Range[10]]]

(*{0.336058,0.976536,0.507958,0.436267,0.1567,0.223463,0.760768,0.996779,0.532131,0.217988}*)

(*{0.112935,0.953623,0.258022,0.190329,0.0245549,0.0499356,0.578768,0.993568,0.283163,0.0475189}*)


• Good One, this solves my problem. But I would like to do this for each row(one histogram plot for each row, as above), to convey my problem I showed you one row. Do I need to change h1 everytime? Or I can make h1 a matrix and change the row ? – L.K. Oct 6 '16 at 10:25
• Just use Part to select the appropriate row from your H1 (squared matrix data) and plot it with RectangleChart. – dionys Oct 6 '16 at 10:28
• +1 .But for large $n$ isn't it a problem. Writing everytime new row or can we make a loop, which will select the row automatically and histogram plot for that? – L.K. Oct 6 '16 at 10:32
• Read the help docs for Map and Part carefully. You can apply Part and generate the plots for all rows by mapping a function over your squared data. You could do it in a loop as well, but it's messier and less efficient. Also, read the help for Table before you resort to procedural for-loops. – dionys Oct 6 '16 at 10:42
• See the edited answer which shows x-axis labels and uniform widths. – dionys Oct 6 '16 at 15:50