How can I create a custom histogram with specific bin widths using Wolfram?

  • Context: MHB 
  • Thread starter Thread starter Jameson
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around creating custom histograms and box plots using Wolfram Alpha and Mathematica. Participants share their attempts to customize bin widths for histograms and express frustrations with the limitations of the online version of Wolfram Alpha compared to Mathematica.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant seeks to create a histogram with specific bin widths using a defined data set and expresses difficulty in customizing the bin width in Wolfram Alpha.
  • Another participant suggests using the syntax for Histogram in Mathematica, specifying the bin width as {.5}.
  • A participant confirms that the suggested command works in Mathematica but not in the online version of Wolfram Alpha.
  • Discussion shifts to creating a box plot, with a participant noting that the suggested command does not work as expected in Wolfram Alpha.
  • Another participant corrects the box plot command to BoxWhiskerChart and shares additional statistical information obtained from Mathematica.
  • Participants discuss the limitations of Wolfram Alpha compared to Mathematica and suggest alternatives, including obtaining a student license for Mathematica or using Python for free.
  • One participant provides a LaTeX code snippet using PGFPlots for creating histograms, suggesting it as an alternative for those needing graphics for documents.

Areas of Agreement / Disagreement

Participants express a general consensus on the limitations of Wolfram Alpha for their needs, but there is no agreement on the best alternative solution, as some advocate for Mathematica while others suggest Python.

Contextual Notes

Participants mention specific commands and functionalities that may not be available in the online version of Wolfram Alpha, indicating a reliance on Mathematica for full capabilities. There are also references to potential costs and licensing options for Mathematica, as well as alternative tools like Python and LaTeX for creating visualizations.

Jameson
Insights Author
Gold Member
MHB
Messages
4,533
Reaction score
13
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?
 
Physics news on Phys.org
Re: Histogram on Wolfram

Jameson said:
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?
 
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. :(
 
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.
 
Jameson said:
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
 
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!
 
Jameson said:
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.
 
Jameson said:
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:

Similar threads

  • · Replies 1 ·
Replies
1
Views
13K
  • · Replies 0 ·
Replies
0
Views
6K
  • · Replies 16 ·
Replies
16
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
2
Views
3K
  • · Replies 152 ·
6
Replies
152
Views
11K