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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to essentially make a scatter plot where instead of points, the markers are bars that connect the point to the bottom of the graph (like a histogram). My problem is that my graph has something like 30 points and the x-axis labels are smashed together. I tried doing it with Histograms to no avail, and tried doing it with BarChart with a bit more success, but there are so many markers on the x-axis that you can't read them. My problems would be solved if I could specify only a few markers at certain positions. Can anyone help?

Below is what the graph looks like: I think it's pretty self-explanatory what the problem is even just by looking at it.enter image description here

share|improve this question
1  
Have you looked at the Filling option of ListPlot[]? – J. M. Feb 19 at 6:25
1  
What @J.M. suggested plus make your own x axis tick labels or tick function – Mike Honeychurch Feb 19 at 6:28
1  
Try plotting your data with ListStepPlot, use the "Center" arguement. – Quantum_Oli Feb 19 at 8:56

It's a good question and something I've dealt with recently when essentially trying to plot a histogram but when I already have the data binned. After using ListLinePlot with InterpolationOrder->0 I discovered the very useful ListStepPlot function. Allow me to demonstrate.

If we have some samples we can just use Histogram:

    samples = RandomVariate[SkewNormalDistribution[4, 1, 2], 100000];
    Histogram[samples, {0, 10, 0.1}, "Probability"]

enter image description here

However, if you already have the data points corresponding to the elements of the histogram, as in your case.

    {binEdges, counts} = HistogramList[samples, {0, 10, 0.1}, "Probability"];
    dataPoints = Transpose[{MovingAverage[binEdges, 2], counts}];

enter image description here

Then as you say, BarChart is not so good:

    BarChart[dataPoints[[;; , 2]], ChartLabels -> dataPoints[[;; , 1]]]

enter image description here

However, ListStepPlot makes things very easy!

    ListStepPlot[dataPoints, "Center", Filling -> Axis]

enter image description here

And you can use all the normal plot styling functionality

    ListStepPlot[dataPoints, "Center", 
      PlotStyle -> RGBColor[0.982864`, 0.7431472`, 0.3262672`], 
      Filling -> Axis, 
      FillingStyle -> Opacity[1], 
      Frame -> True, 
      PlotRangePadding -> None, 
      GridLines -> Automatic]

Good Luck!

enter image description here

share|improve this answer
    
Thank you so much! – user37840 Feb 21 at 19:16

One way would be like the following. Assume that this is your list:

lst = Table[{i, i^(1/2)*Exp[-i]}, {i, 0, 4, 0.05}];

And here is you histogram-like plot:

 Show[Graphics[{Blue, 
     Rectangle[{#[[1]] - 0.025, 0}, {#[[1]] + 0.025, #[[2]]}]}, 
    AspectRatio -> 1, Axes -> True] & /@ lst]

looking as follows:

enter image description here

Have fun!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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