|
[Date Index]
[Thread Index]
[Author Index]
Re: DateListBarChart / Ticks in BarChart
- To: mathgroup at smc.vnet.net
- Subject: [mg104529] Re: DateListBarChart / Ticks in BarChart
- From: Armand Tamzarian <mike.honeychurch at gmail.com>
- Date: Tue, 3 Nov 2009 02:54:10 -0500 (EST)
- References: <hcjisk$jld$1@smc.vnet.net>
On Nov 1, 3:03 am, Luci Ellis <l... at verbeia.com> wrote:
> Dear MathGroupers,
> I am trying to set up some custom functions/ option settings to
> replicate the standard look and feel of charts as used by my employer.
> These are currently done in DeltaGraph, but I would like to be able to
> generate charts directly in Mathematica so that I don't have to worry
> about the additional (Export to Excel -> Import into DeltaGraph ->
> bother a research assistant ) steps.
>
> Most of our charts are of time series, and I have been able to
> replicate the look for line graphs by customising DateListPlot[]. But I
> can't replicate the effect for bar charts. Our standard is to put a
> tick every X periods (say, to mark off every year or every quarter) and
> then centre the date label in that region. I am having serious problems
> putting the ticks in exactly the right place for bar charts. Adding up
> bar widths and (prespecified) BarSpacings never quite seems to work.
> (If you need an example of what I'm trying to do, have a look at the
> two graphs on the left-hand side of the first page inhttp://www.rba.gov.a=
u/ChartPack/output_expenditure_activity_fincon.pdf
> -- I have the equivalent of the bottom right-hand graph on that page
> working.)
>
> I tried using a Thickness style for Filling of a non-joined
> DateListPlot, but it doesn't work because the thickness also applies to
> the ends of the line -- ie the "rectangle" doesn't actually stop at the
> axis but goes past it by an amount equal to the value of Thickness.
>
> There is also the issue that I will need to combine Line and Bar charts
> for certain applications. We often plot a year-ended percentage change
> as a line and then the quarterly or monthly percentage change as small
> bars on the same axis.
>
> Can anyone offer any guidance on placement of ticks in BarChart, and
> combining them with DateListPlots? Or, failing that, making
> DateListPlots look like BarCharts?
>
> Thanks in advance,
> Luci
This requiring some further work but seems to do what you want.
Make some sample data ...I guess it might come in this sort of format
someData = Flatten[Table[{ToString[i] <> "q" <> ToString[j], RandomReal
[{-10, 10}]}, {i, 1999, 2008}, {j, 1, 4}], 1];
You will be able to convert it to this format easily enough:
data1 = Flatten[Table[{{i, j}, RandomReal[{-5, 5}]}, {i, 1999, 2008},
{j, 1, 4}], 1];
data2 = Flatten[Table[{{i, j*3}, RandomReal[{8, 20}]}, {i, 1999,
2008}, {j, 1, 4}],1];
(* need to tweek this for leap years *)
dates[{year_, quarter_}] := Which[
quarter == 1, DatePlus[{year, 1, 0}, #] & /@ Range[90],
quarter == 2, DatePlus[{year, 4, 0}, #] & /@ Range[91],
quarter == 3, DatePlus[{year, 7, 0}, #] & /@ Range[92],
quarter == 4, DatePlus[{year, 10, 0}, #] & /@ Range[92]
];
barData = Thread[{dates[#[[1]]], #[[2]]}] & /@ data1;
p1 = DateListPlot[barData, Joined -> False, Filling -> 0];
p1 = DeleteCases[p1, _Point, \[Infinity]];
p2 = DateListPlot[data2, Joined -> True, PlotStyle -> Thick];
Show[p2, p1, PlotRange -> All]
I don't know how to get the year labels centred. Maybe someone else
can offer a suggestion.
Mike
Prev by Date:
Re: Using Mathematica 5.2 and 7.01 with separate settings
Next by Date:
Washington DC Area Mathematica Special Interest Group
Previous by thread:
DateListBarChart / Ticks in BarChart
Next by thread:
Re: DateListBarChart / Ticks in BarChart
|