How is the BarSpacing option really implemented in Mathematica?

I am trying to implement a DateListBarChart function that takes outdated data and displays a histogram with the same placements as DateListPlot . It is very important that they display data in the same horizontal position if the same data was specified, so they can be combined using Show . It's hard for me to get the settings for BarSpacing to the right, so that the horizontal range of the chart does not change, and the bars remain basically in the same place.

I couldnโ€™t get the correct scaling, so BarSpacing->{0.2,0.3} will cause 20% of the x-axis length available for this group of bars to be occupied by the distance between the bands in this group and 30% as the interval between the groups bars. For technical reasons, I do this by passing things to a RectangleChart . According to the documentation, BarSpacing considered as absolute units in RectangleChart . Obviously, the absolute sizes of the gaps should be smaller if there are more, and the bars should be narrower.

Some examples:

 arList = FoldList[0.9 #1 + #2 &, 0.01, RandomReal[NormalDistribution[0, 1], 24]] {0.01, 0.334557, 2.02709, 1.1878, 1.9009, 3.08604, 2.36652, 3.04111, 3.32364, 3.22662, 3.12626, 2.59118, 1.69334, 1.21069, 0.23171, 0.689415, -0.852649, -0.124624, 0.58604, -0.481886, 0.221074, -0.300329, 2.36137, 0.427789, -1.47747} dists = RandomChoice[{3, 4}, Length[arList]] {4, 4, 4, 3, 4, 3, 4, 3, 4, 4, 3, 4, 4, 3, 4, 4, 4, 4, 3, 4, 3, 3, 3, 3, 3} 

Results in:

 RectangleChart[Transpose[{dists - 0 - 0/2, arList}], PlotRange -> {{0, 100}, {-2, 4}}, ChartStyle -> EdgeForm[None], Frame -> True, GridLines -> Automatic, BarSpacing -> {0, 0}] 

enter image description here

 RectangleChart[Transpose[{dists - 0.7 - 0.5/2, arList}], PlotRange -> {{0, 100}, {-2, 4}}, ChartStyle -> EdgeForm[None], Frame -> True, GridLines -> Automatic, BarSpacing -> {0.7, 0.5}] 

enter image description here

Notice how the data does not cover the same distance along the x axis as a previous example.

He becomes even more messy when he tries to draw several rows (the same in this example, for illustration).

 RectangleChart[ Transpose[{{dists - i/2 - j/2, arList}, {dists - i/2 - j/2, arList}}, {2, 3, 1}], PlotRange -> {{0, 180}, {-2, 4}}, ChartStyle -> EdgeForm[None], Frame -> True, Ticks -> None, GridLines -> Automatic, BarSpacing -> {i, j}] 

enter image description here

I've been clinging to finding the right formula for a long time, so the BarSpacing settings for a custom function (not shown here) cause the correct distances and bandwidths, so the range of horizontal plots doesn't change, as BarSpacing does.

What am I missing?

EDIT: In response to belisarius, this is an example of where I'm heading. It works like (the bars do not quite match the line, but these are probably the dates that I use), but cases with complex bars cannot be built with bars where they should be, like any histogram itself, where There are several series. (I am very proud of the algorithm for placing date stamps: the forces that work do not want to abandon this look.)

enter image description here

And here is one that just doesn't work. Data must fill the horizontal range. (The various strips of width are intentional - this is a combination of annual and quarterly data.)

enter image description here

EDIT 2

I remember why I did not use Filling in DateListPlot to draw bars, as in Mike Hanicharch's package - if you have something other than very skinny bars, they end up on the top edge in the wrong place.

 DateListPlot[{dateARList}, PlotStyle -> {AbsolutePointSize[6], Yellow}, Filling -> {1 -> 0}, FillingStyle -> {1 -> {{AbsoluteThickness[12], Darker[Red, 0.25]}}}, PlotRange -> All] 

enter image description here

+7
source share
2 answers

Perhaps using a ChartElementFunction instead of BarSpacing . For example, the barplot in the code will display a histogram in which each column has gapl fields on the left and gapr on the right, where gapl and gapr are fractions of the total bandwidth

 scale[{{xmin_, xmax_}, {ymin_, ymax_}}, {gapl_, gapr_}] := {{xmin (1 - gapl) + xmax gapl, ymin}, {xmax (1 - gapr) + xmin gapr, ymax}} barplot[dists_, arList_, {gapl_, gapr_}, opts___] := RectangleChart[Transpose[{dists, arList }], opts, Frame -> True, GridLines -> Automatic, BarSpacing -> 0, ChartElementFunction -> (Rectangle @@ scale[#, {gapl, gapr}] &)] 

Using:

To display the original histogram without spaces

 barplot[dists, arList, {0, 0}] 

rectangle chart with no gaps

This will build a histogram with a difference of 0.2 on both sides, which will lead to a histogram with gaps of 0.4 times the total width of the bars. Please note that the positions of the bars coincide with the positions in the first figure.

 barplot[dists, arList, {0.2, 0.2}] 

barchart with gaps

You can build several series by doing something like

 Show[barplot[dists, arList 0.9, {0, 0.5}], barplot[dists, arList 0.8, {0.5, 0}, ChartStyle -> LightGreen]] 

two series in one plot

+9
source

You can remove the complaint against FillingStyle using CapForm["Butt"] .

 list = {0.01, -0.81, 0.12, 0.81, 1.79, 1.1, 0.41, 1., 1.33, 1.08, 2.16, 1.13, 1.92, 1.64, 1.31, 1.94, 1.71, 0.91, 2.32, 0.95, 1.29, 1.28, 2.97, 4.45, 5.11} DateListPlot[list, {2000, 8}, PlotStyle -> {AbsolutePointSize[6], Yellow}, Filling -> {1 -> 0}, FillingStyle -> {1 -> {{CapForm["Butt"], AbsoluteThickness[14], Darker[Red, 0.25]}}}, PlotRange -> {0, 6}, ImageSize -> 400] 

enter image description here

+4
source

All Articles