Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to create a bar chart from two different data sets.

data = {{38, 4.637, 88.3238, 2.26935}, {277, 75.724, 1442.36, 5.07813}, {561, 72.623, 1383.3, 2.39955}, {253, 32.727, 623.371, 2.39955}, {1305, 181.438, 3455.96, 2.58557}}


data = {{27, 93.14, 1816.67, 67.2842}, {92, 248.898, 4854.7, 52.7685}, {510, 1681.48, 32796.8, 64.3075}, {234, 933.986, 18217.2, 77.8512}, {443, 4117.78, 80316.2, 181.301}}

These two charts have to have the same range on the y axis (0, 100000), so they can be compared easily. So I can still see the bars for the lower values, I set the ScalingFunctions to "Log".

I plot them both with this code:

plot1 = BarChart[data, PlotRange -> {0, 12}, ScalingFunctions -> "Log"]

However, when I create the first plot, the bars don't start at the y-axis, but below, whereas the second data set has the bars start at 10, not at 0. I am using Mathematica 8. If I use PlotRange-> {Automatic, 12}, then I don't have the problem of the bars being off the x axis, however they still start at different values (0 and 10). Look:

Mathematica graphics

Does somebody know what I am doing wrong?

share|improve this question

closed as off-topic by Karsten 7., MarcoB, Pickett, Silvia, Lou Oct 17 at 16:09

  • The question does not concern the technical computing software Mathematica by Wolfram Research. Please see the help center to find out about the topics that can be asked here.
If this question can be reworded to fit the rules in the help center, please edit the question.

Seems like a bug to me. – s0rce Mar 14 '13 at 22:03
Log plots can never start at zero, of course (the scale would have to be infinitely long). So, when you force it to be that way with your PlotRange setting errors are bound to occur. With the data as it is, I also don't see why you would want to restrict the upper range to 12. – Sjoerd C. de Vries Mar 15 '13 at 7:08
I want the two graphs to have the same plotted range along y, so the height of the bars of the same colour can be easily compared, without taking different y axis ranges into account. The highest value in my values is 80k, and a maximum log plot range of 12 gives me 100k as my maximum value. However setting the plot range is not that much of a problem, but the plots in the second case starting at 10 is the bigger one. – Grassi Mar 17 '13 at 5:11
I'm voting to close this question as off-topic because a Log scale can't start at zero. – Karsten 7. Oct 16 at 19:53
It appears that in version 8 the PlotRange values are in log values when there is a log transformation. But now in version 10.2 those values are expected to be in the original units irrespective of the ScalingFunctions (I think). What happens when you use 1 for the lower limit for each? That should put them at the same baseline. (At least that works in version 10.2.) – Jim Baldwin Oct 16 at 22:59

3 Answers 3

It seems a bug that happens when the minimum value across all the lists is greater than E:

data = Table[{E^i, RandomInteger[{10, 20}]}, {i, 5}]
 BarChart[#, ScalingFunctions -> "Log", PlotRange -> {0., 12.}] & /@ {data, data[[2 ;;]]}]

Mathematica graphics

share|improve this answer
Is there a way to have an "invisible" value added, that is in the data, registered when creating the actual plot but not shown, to work around that problem? Just so I can have a value lower than E theoretically in the plot ... – Grassi Mar 14 '13 at 23:01
@Grassi Fixing it is more complicated than that. Try for example with data = Table[{E^i, RandomInteger[{10, 20}]}, {i, 0, 5}] – belisarius has settled Mar 14 '13 at 23:20
In that case I'll probably stick with two graphs where the scales are not the same. Does anybody know if it happens in Mathematica 9 too? – Grassi Mar 15 '13 at 1:08

First of all, there is no zero on a logarithmic scale. Thus the origin cannot possibly be at 0.

The following is however a good and relevant question: how to make the two plots use the same origin (whatever that may be). Accomplishing that, unfortunately, doesn't seem to be a trivial task in version 9 and earlier, but it's east since version 10.0. Here's why:

For many charting and plotting functions, PlotRange is an overloaded option. Normally, PlotRange controls the coordinate bounds within the frame. It only affects how existing graphics elements are shown within the frame. But for many plotting functions it also controls how those graphics are generated.

For BarChart, PlotRange is just a standard graphics option up to version 9. It does not affect how the bars are generated, and does not know about the logarithmic coordinates.

Since version 10.0, it does affect how the bars are drawn, and where their origin will be. Now you can specify the plot range in data coordinates instead of (linear) plot coordinates. We could use e.g. the plot range PlotRange -> {1, 10^5} for both plots:

enter image description here

But you still have to keep in mind that on a logarithmic scale there's no zero, so the bars cannot start at zero. They can start at 1, like here. Also, the length of bars is meaningless to compare (as in one bar is twice as tall as the other). Only the difference in their length is meaningful, not their ratio.

For the reasons above, I do not consider this a bug, simply a missing feature in v9 (i.e. that PlotRange is not overloaded for BarChart in v9).

share|improve this answer

This is not an answer, but an extended comment with graphics.

This is fixed in V10.2. In that version

  {BarChart[d1, PlotRange -> {0, Automatic}, ScalingFunctions -> "Log"], 
   BarChart[d2, PlotRange -> {0, Automatic}, ScalingFunctions -> "Log"]}]



which are charts with default plot ranges.

share|improve this answer
Perhaps PlotRange -> {1, 10^5} is more suitable, as the OP stated "I want the two graphs to have the same plotted range along y, so the height of the bars of the same colour can be easily compared ...". – Karsten 7. Oct 17 at 0:07
@Karsten7. Not trying to solve OP's problem -- just showing the bug is fixed in 10.2 – m_goldberg Oct 17 at 0:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.