Welcome to our community

Be a part of something great, join today!

Histogram/Boxplot on Wolfram

  • Thread starter
  • Admin
  • #1

Jameson

Administrator
Staff member
Jan 26, 2012
4,052
I'm trying to create a simple histogram with custom bin widths. I want the data to be graphed over the ranges:

$[(0,.5],(.5,1],(1,1.5],(1.5,2],(2,2.5],(2.5,3],(3,3.5])$

Here is my data set:

{0.45,0.45,0.473,0.507,0.457,0.452,0.453,1.215,1.256,1.145,1.085,1.066,1.111,1.364,1.254,1.396,1.575,1.617,1.733,2.753,3.186,3.227,3.469,1.911,2.588,2.635,2.725}

If I enter this into Wolfram Alpha:

Code:
Histogram[{0.45,0.45,0.473,0.507,0.457,0.452,0.453,1.215,1.256,1.145,1.085,1.066,1.111,1.364,1.254,1.396,1.575,1.617,1.733,2.753,3.186,3.227,3.469,1.911,2.588,2.635,2.725}]
I get a graph but I can't seem to customize the bin width. Any ideas?
 

Chris L T521

Well-known member
Staff member
Jan 26, 2012
995
Re: Histogram on Wolfram

I'm trying to create a simple histogram with custom bin widths. I want the data to be graphed over the ranges:

$[(0,.5],(.5,1],(1,1.5],(1.5,2],(2,2.5],(2.5,3],(3,3.5])$

Here is my data set:

{0.45,0.45,0.473,0.507,0.457,0.452,0.453,1.215,1.256,1.145,1.085,1.066,1.111,1.364,1.254,1.396,1.575,1.617,1.733,2.753,3.186,3.227,3.469,1.911,2.588,2.635,2.725}

If I enter this into Wolfram Alpha:

Code:
Histogram[{0.45,0.45,0.473,0.507,0.457,0.452,0.453,1.215,1.256,1.145,1.085,1.066,1.111,1.364,1.254,1.396,1.575,1.617,1.733,2.753,3.186,3.227,3.469,1.911,2.588,2.635,2.725}]
I get a graph but I can't seem to customize the bin width. Any ideas?
The general syntax for Histogram is Histogram[data,bspec,hspec] (but hspec isn't needed here). So the bspec you want to specify is {.5} (since you seem to be splitting the data into intervals that are .5 units long); thus, the command

Code:
Histogram[{0.45,0.45,0.473,0.507,0.457,0.452,0.453,1.215,1.256,1.145,1.085,1.066,1.111,1.364,1.254,1.396,1.575,1.617,1.733,2.753,3.186,3.227,3.469,1.911,2.588,2.635,2.725},{.5}]
gives me the following graph in Mathematica:


Is this what you're after?
 
  • Thread starter
  • Admin
  • #3

Jameson

Administrator
Staff member
Jan 26, 2012
4,052
Re: Histogram on Wolfram

Yep that's it and exactly what I typed into Wolfram Alpha, but apparently it doesn't work on the online version. :(
 
  • Thread starter
  • Admin
  • #4

Jameson

Administrator
Staff member
Jan 26, 2012
4,052
Now I'm trying to do a boxplot (this is ridiculously simple I know - it's a class I have to take) and according to the online guide this code should work:

Code:
BoxWhiskerPlot[{0.45,0.45,0.473,0.507,0.457,0.452,0.453,1.215,1.256,1.145,1.085,1.066,1.111,1.364,1.254,1.396,1.575,1.617,1.733,2.753,3.186,3.227,3.469,1.911,2.588,2.635,2.725}]
but alas, nothing. I found another site to make the box plot but I wish this could be done online at W|A.
 

Chris L T521

Well-known member
Staff member
Jan 26, 2012
995
Now I'm trying to do a boxplot (this is ridiculously simple I know - it's a class I have to take) and according to the online guide this code should work:

Code:
BoxWhiskerPlot[{0.45,0.45,0.473,0.507,0.457,0.452,0.453,1.215,1.256,1.145,1.085,1.066,1.111,1.364,1.254,1.396,1.575,1.617,1.733,2.753,3.186,3.227,3.469,1.911,2.588,2.635,2.725}]
but alas, nothing. I found another site to make the box plot but I wish this could be done online at W|A.
It should be BoxWhiskerChart. Plugging that code (after making that correction) into Mathematica gives me the following:


There was also some additional information you get when you hover over the output in Mathematica:

Max: 3.469
75%: 2.588
Median: 1.256
25%: 0.507
Min: 0.45
 
  • Thread starter
  • Admin
  • #6

Jameson

Administrator
Staff member
Jan 26, 2012
4,052
I just need to get a copy of Mathematica on my laptop. Wolfram Alpha doesn't have the full functionality Mathematica does and this code still doesn't work there. Thanks for the help!
 

Chris L T521

Well-known member
Staff member
Jan 26, 2012
995
I just need to get a copy of Mathematica on my laptop. Wolfram Alpha doesn't have the full functionality Mathematica does and this code still doesn't work there. Thanks for the help!
Yea, no problem. Since you're a student, you can get Mathematica for about $140 (if you get the standard edition [which is the one I have]; its cheaper if you want to have it for a year or even a semester [see here for more info]). If you get the standard edition, it's yours to keep even after you're done with school.
 

dwsmith

Well-known member
Feb 1, 2012
1,673
I just need to get a copy of Mathematica on my laptop. Wolfram Alpha doesn't have the full functionality Mathematica does and this code still doesn't work there. Thanks for the help!
Why pay $140 when Python is FREE. Also, every school I have been to gave me a site license. You should look into that before paying for it to. However, still go with Python.

If you are going to put this graphics in a \(\LaTeX\) document, you could always create it in PGFplots. Here is your code with 7 bins. You would have to look up how to specify bin width but that shouldn't be too hard.

PGFPlots documentation: CTAN: Package pgfplots



Latex Code:

\documentclass[tikz]{standalone}
\
usepackage{pgfplots}
\pgfplotsset{compat = 1.8}
\usepgfplotslibrary{statistics}
\begin{document}
\begin
{tikzpicture}
\begin{axis
}[
ybar interval,
xticklabel =
{$(\pgfmathprintnumber\tick, %
\pgfmathprintnumber\nexttick]$},
font = \scriptsize,
width = 15cm
]

\addplot+[hist = {bins = 7}]
table[row sep = \\, y index = 0]{
data\\
0.45\\ 0.45\\ 0.473\\ 0.507\\ 0.457\\ 0.452\\ 0.453\\ 1.215\\ 1.256\\
1.145\\ 1.085\\ 1.066\\ 1.111\\ 1.364\\ 1.254\\ 1.396\\ 1.575\\ 1.617\\
1.733\\ 2.753\\ 3.186\\ 3.227\\ 3.469\\ 1.911\\ 2.588\\ 2 .635\\ 2.725\\
};
\end
{axis}
\end
{tikzpicture}
\end{document
}
 
Last edited: