7

I want to plot the following data as steps:

Ydata={2,4,6,8,10};
Xdata={2,8,18,34,64};
halfbinsize={2,4,6,10,20};

I want to include the bin-size (or half-bin-size) into account. So in this case the first bin will be dx=[0-4] with a central value at Xcentral=2. For the next bin dx=[4-12] with central value Xcentral=8. Similarly for the next bins dx=[12-24], Xcentral=18, dx=[24-44], Xcentral=34, dx=[44-84], Xcentral=64...

Now with ListStepPlot I can have a bin-distribution, however, it seems like it takes the steps-sizes automatically.

ListStepPlot[TemporalData[{Ydata},{Xdata}],
Center,
PlotRange->{{-10.0,90.0},{0,12}},
Mesh->Full,
Frame->True,
FrameTicks->{
{#,#}&@(Charting`ScaledTicks[{Identity,Identity},"TicksLength"->{0.03,0.015}][##,{5,11}]&),
{#,#}&@(Charting`ScaledTicks[{Identity,Identity},"TicksLength"->{0.03,0.015}][##,{11,11}]&)}
]

enter image description here

As it is shown, although the central values are shown correctly, the steps (or bins) are rather different. For example for the first bin, it takes the bin-size to be 6 (probably it just looks at two successive x-data and from there it derives the bin-size automatically, in this case, 8-2=6 and distributes 6 equally around 2), and thus plots as dx=[-1,5] with Xcentral=2.

My question is: How should I force ListStepPlot to use user-defined bins with correct central value?

BabaYaga
  • 1,836
  • 9
  • 19

1 Answers1

5
Clear["Global`*"]

Ydata = {2, 4, 6, 8, 10};
Xdata = {2, 8, 18, 34, 64};
halfbinsize = {2, 4, 6, 10, 20};

Using ListPlot with Around

ListPlot[
 Transpose[{Around @@@
    Transpose[{Xdata, halfbinsize}], Ydata}],
 PlotRange -> {{-10.0, 90.0}, {0, 12}},
 Frame -> True,
 FrameTicks -> {
   {#, #} &@(Charting`ScaledTicks[{Identity, Identity},
        "TicksLength" -> {0.03, 0.015}][##, {5, 11}] &),
   {#, #} &@(Charting`ScaledTicks[{Identity, Identity},
        "TicksLength" -> {0.03, 0.015}][##, {11, 11}] &)}
 ]

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • 1
    So with ListStepPlot it is not that straightforward for this purpose? The reason I wanted to stick to that is, that it is very easy there to use other features like having a histogram-like or step-like plot, filling the area between two sets of Ydata very easily using Filling etc. – BabaYaga Jun 12 '22 at 15:45