2
$\begingroup$

How can I create a date diagram like that?

enter image description here

Let's say that the counting is done each couple of days, and the right bar represents the counting totals.

$\endgroup$
  • 1
    $\begingroup$ You can construct it using graphics primitives such as Rectangle. What is the input data you would use to make the plot and what have you tried so far? It is not difficult but it takes a bit of work, so it would be great if you could clarify where you got stuck and ask for more specific help ... $\endgroup$ – Szabolcs Mar 1 '16 at 14:12
  • $\begingroup$ Or you might try ArrayPlot $\endgroup$ – Harry Mar 1 '16 at 14:21
  • $\begingroup$ Yes, ArrayPlot will be simpler but I think it won't make it possible to draw a frame only around some of the little rectangles. $\endgroup$ – Szabolcs Mar 1 '16 at 14:37
  • $\begingroup$ clarifying the question, the totals can be simple countings, like this: day 1,2 = 130; day 3,4 = 400; day 5,6= 754; etc... Note that the max count 800 - right bar- could be any number since totals for couple of days could be 1230, 5.000 etc. Or we can stablish a upper limit based on the max totals of a certain day counting. $\endgroup$ – locometro Mar 1 '16 at 16:04
  • $\begingroup$ To simplify let's assuming countings for each day, forget couples days $\endgroup$ – locometro Mar 1 '16 at 16:10
3
$\begingroup$

If you don't mind a few differences here and there, the biggest bang for the buck is ArrayPlot/MatrixPlot

Suppose you have you data in a nested list, gathered by month

ts[[1,1]] == (* jan/01 *)
ts[[2,20]] == (* feb/20 *)
(* and so on *)

You can plot them directly

MatrixPlot[ts, 
 ColorFunctionScaling -> False, 
 ColorFunction -> ColorData[{"PlumColors", {0, 800}}], 
 PlotLegends -> Automatic, 
 FrameTicks -> {Thread@{Range[12], monthNames}, Range[2, 31, 2]},
 AspectRatio -> 1,
 Epilog -> {Red, Thick, Line[{{0, 12 - 3}, {31, 12 - 3}}]}]

Month

If you spend some time with the options (Mesh, FrameTicks, ColorFunction) you might get a better approximation!

$\endgroup$
  • $\begingroup$ Interesting! I didn't realize that MatrixPlot supported ragged arrays. Unfortunately it doesn't show the raggedness in the mesh (Mesh -> All) $\endgroup$ – Szabolcs Mar 1 '16 at 15:12
  • $\begingroup$ I must confess I was expecting it to fail at some point, but since it never did... The Mesh issue is why a chose a palette with Black as the zero color, since White is taken as "Null". It's not exactly the same, but I hope it's somehow useful! $\endgroup$ – Aisamu Mar 1 '16 at 15:16
  • $\begingroup$ Probably, a temperature color would be better? $\endgroup$ – locometro Mar 1 '16 at 16:22
  • 1
    $\begingroup$ Unfortunately, ColorData["TemperatureMap"] has White as the middle color, and ColorData["VisibleSpectrum"] does not work with the custom range option (a bug, perhaps). $\endgroup$ – Aisamu Mar 1 '16 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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