Creating Histogram with Varying Bin Width


In Origin, histogram is plotted with equal bin width. But sometimes user wants to plot histogram with varying bin width to better illustrate the distribution of the data. This blog will show you how to do a frequency count with user-defined bin boundaries and then plot the result as a column plot with with varying column width to get the effect of histogram with varying bin width. You can follow along with this blog by running Origin, pressing F11 and on the Graph Samples tab searching All Plot Types for “varying”.


Here we have a modified set of sediment grain size data from a USGS survey.  The distribution of data column C however varies considerably between different grain sizes. For this reason we’ll create a new column D and set Long NameBoundaries and enter some custom intervals- grain sizes between, 0, 25, 50, 100, 150, 200, 300, and 450 microns. After entering these values, we’ll select the grain size column C and bin our frequencies by going to Statistics>Descriptive Statistics>Frequency Counts to calculate counts in our custom boundaries.


In this dialog, set  Specify Binning Range by to User Defined Boundaries. Then in the Binning Range Data field, click > button and pick D(Y): Boundaries. Leave the rest of the settings as their defaults and click OK. A result sheet will be added in the workbook.


After closing the dialog we should see the frequency count worksheet containing the bin center, end and the counts for each bin. Add a new column and set its Long Name as Bin Width. We will calculate the bin width values using the Set Column Values dialog . The expression to enter: i<2? (col(B)[i]): (col(B)[i]-col(B)[i-1])


Once this has been done, we’ll select the Count column (column C) and plot the column plot below.


It uses Bin Center column (Column A) as X position of each column and they are plotted with same width. Some may overlap since X positions are close to each other.

To modify their width to fill the entirety of our x-axis, double-click on the graph to open the Plot Details dialog and then in the Spacing tab of our plot change the Width (in %) to be represented by Col(E): “Bin Width” with a scaling factor of 0. When the scaling factor is set to 0, Origin will use the widths given in column E as proportional sections of the total x-range; or rather their width will fill the entirety of the x-axis between the min and max of our data.


Click OK, our column graph should appear as it does above due to the default margin settings of Origin.



We can change the axis from and to to be the from 0 to 450, our customized grain size boundary.


We have now created a histogram with varying bin width illustrating the disparate frequency of different particle sizes in our sediment data. With some final touches, this is how you create a variable width column graph in Origin and OriginPro.



2 Comments on “Creating Histogram with Varying Bin Width”

  1. I have some issues related with the new col(e). I do not understand the values what you are settin into the col(e). Can you please detail what what means? I understood from the script that the first is the sheet, then comes the column and after that [2:9]. What this mean? For ex. my boundaries I have in the the Sheet2 col(b). How the script would look like?
    Thank you for your help.

    1. Hi Levente,

      You are right. User can directly use the coL(b) in Sheet2 to calculate each bin width instead of using the original col(E) on 1st sheet.

      So in Set Column Values dialog, no need to define any variable in Before Formula Script. In the Formula box, enter
      i<2? (col(B)[i]): (col(B)[i]-col(B)[i-1])

      This will count bin width based on column B. I saw the screenshot also have issues. So I will correct the blog.

      Thanks, Snow

Leave a Reply

Your email address will not be published. Required fields are marked *