4
$\begingroup$

I would like to present data color coded in a bar.

My data look like the following:

 {-2.5,-1.0,0.1,0.5,-0.24,-0.58,-0.58,-0.25,-1.4,2.1,1.8,-2.5,1.97}

I would like to create a horizontal bar and each part of the bar should be colored according to the number value of each data point. The color scheme should be getting the bluer the smaller the value below zero and increasingly red for values larger than zero. (The color scheme is not important, I just want to make the different values visible). All parts of the bar should be of the same length. I have no idea where to start and don't know if a stacked bar chart is the way to go or if I should better represent each value with a rectangle graphics object that I combine in the end. The image below is just to show you the kind of bar I would like to create (very roughly).

Here is an image to make clearer what I am looking for (very roughly)

$\endgroup$
  • $\begingroup$ Your sample output suggests that you may wish to sort the data before plotting it. Is that the case? $\endgroup$ – bbgodfrey Jan 5 '16 at 19:20
3
$\begingroup$
data = {-2.5, -1.0, 0.1, 0.5, -0.24, -0.58, -0.58, -0.25, -1.4, 2.1, 1.8, -2.5, 1.97};

Graphics[Raster[{Rescale@data}, 
  ColorFunction -> (Blend[{{0, Blue}, {1, Red}}, #] &)], 
  AspectRatio -> .3]

enter image description here

$\endgroup$
2
$\begingroup$
tab = Table[{m, m}, {m, -2.5, 2.5, 0.1}]

ListDensityPlot[Transpose[tab], 
 ColorFunction -> (ColorData[{"TemperatureMap", {-2.5, 2.5}}][#] &), 
 ColorFunctionScaling -> False, PlotRangePadding -> 0, 
 PlotRange -> All, AspectRatio -> 1/8, Frame -> False]
$\endgroup$
  • $\begingroup$ You can exchange the colorscheme. Just figure out Mathematica help and search for ColorSchemes. If you want to keep the rectangular shapes, try it this way: Graphics[Table[{Blend[{Red, Green}, i], EdgeForm[Gray], Rectangle[{4 i, 0}]}, {i, 0 - 1/4, 1 + 1/4, 1/4}]] $\endgroup$ – Kay Jan 5 '16 at 18:28
  • $\begingroup$ You can update your answer, instead of adding useful information in a comment. Also it would be better if you posted an image as well so that we can more easily judge the quality of the answer, which will make us (probably) more likely to vote for it. $\endgroup$ – C. E. Jan 5 '16 at 18:47
2
$\begingroup$

Here's one way to do it with rectangles:

data = {-2.5, -1.0, 0.1, 0.5, -0.24, -0.58, -0.58, -0.25, -1.4, 2.1, 1.8, -2.5, 1.97};

colors = ColorData["AvocadoColors"] /@ Rescale[data];
rectangles = Table[Rectangle[{x, 0}, {x + 1, GoldenRatio}], {x, 0, Length@colors, 1}];

Graphics@Riffle[colors, rectangles]

Mathematica graphics

$\endgroup$
0
$\begingroup$
list = {-2.5, -1.0, 0.1, 0.5, -0.24, -0.58, -0.58, -0.25, -1.4, 2.1, 1.8, -2.5, 1.97};
ArrayPlot[{list}, ColorFunction -> "TemperatureMap"]

enter image description here

$\endgroup$

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.