Here comes a sample set of data
data = {{1.03971, 0.00617284, 12.11, 0.227037, 1},
{1.0231, 0.0216931, 27.23, 1.40703, 1},
{1.02864, -0.0294533, 1450, 0.0821789, 9},
{1.01636, -0.0149912, 16.89, 1.02227, 1},
{0.938865, -0.00899471, 68.94, 0.0000322202, 9},
{0.955953, 0.0199295, 1.89, 0.00448189, 9},
{1.03321, 0.0329806, 84.23, 0.094761, 1},
{1.02406, 0.0393298, 13.21, 0.099565, 2},
{0.9728, -0.00194004, 1000, 0.000845306, 0},
{1.00649, -0.00582011, 62.1, 0.0286736, 1}};
The first two columns correspond to the coordinates $(x,y)$, while the other three are some indicators. Now I want the following:
Create a plot of the $(x,y)$ points where the color is according to the value of the third column. In particular
- All points for which the fifth element is 1 should be colored in a blue tone (DeepSeaColors), where dark blue indicate high values of the third column.
- All points for which the fifth element is 9 should be colored in a Rainbow tone, where light reddish color should suggest low values of the third column
- All points for which the fifth element is not 1 or 9 should be colored in white or transparent color.
First we select the corresponding points
data1 = Select[data, #[[5]] == 1 &];
data9 = Select[data, #[[5]] == 9 &];
Then we re-scale them and we also define a color function
valrange1 = {0, 100};
valrange9 = {0, 10};
data1[[All, 3]] = Rescale[data1[[All, 3]] // N, valrange1];
data9[[All, 3]] = Rescale[data9[[All, 3]] // N, valrange9];
colfunc[x_, cf_] := ColorData[cf][1 - x[[3]]];
The respective graphics are
g1 = Graphics[{PointSize[0.005], Point[#[[1 ;; 2]], VertexColors -> colfunc[#, "Rainbow"]] & /@ data1}];
g9 = Graphics[{PointSize[0.005], Point[#[[1 ;; 2]], VertexColors -> colfunc[#, "DeepSeaColors"]] & /@ data9}];
Finally we show them together (this is the plot of the actual data set)
Obviously there is something missing. In fact we need two color bars in order to explain the different colors.
First a vertical color bar corresponding to points with fifth column equal to 1.
Clear[colorbar]
colorbar[{min_, max_}, colorFunction_: Automatic, divs_: 150] :=
DensityPlot[y, {x, 0, 0.1}, {y, min, max}, AspectRatio -> 10,
PlotRangePadding -> 0, PlotPoints -> {2, divs}, MaxRecursion -> 0,
Frame -> True,
FrameLabel -> {{None, Row[{Subscript["t", "esc"]}]}, {None, None}},
LabelStyle -> Directive[FontFamily -> "Helvetica", 20],
FrameTicks -> {{None, All}, {None, None}},
FrameTicksStyle -> Directive[FontFamily -> "Helvetica", 20, Plain],
ColorFunction -> colorFunction]
Then
With[{opts = {ImageSize -> {Automatic, 400}}, cf = "Rainbow"},
Row[{Show[{g1, g9}, Axes -> False, Frame -> True,
FrameLabel -> {"x", "y"}, RotateLabel -> False,
LabelStyle -> Directive[FontFamily -> "Helvetica", 20],
AspectRatio -> 3/4, ImagePadding -> {{90, 10}, {60, 40}}, opts],
Show[colorbar[valrange1, ColorData[cf][1 - #] &],
ImagePadding -> {{10, 80}, {60, 40}}, opts]}]]
which gives
Now I want the following:
Add a second horizontal color bar at the upper part of the frame corresponding to the DeepSeaColors of points with fifth column equal to 9. The range of this color bar should go from 0 to 10, while the title above it should read t_col. Note that the width of the color bar should match the width of the frame.
Any ideas?
Many thanks in advance!
Show[Legended[g1, BarLegend["Rainbow", 1 - data1[[All, 3]]]], Legended[g9, Placed[BarLegend["DeepSeaColors", 1 - data9[[All, 3]], LegendLayout -> "Row"], Top]]]
? $\endgroup$SciDraw
. There, you can define aMultipanel
of 2x2 dimensions and place the color bars in {1,1} and {2,2}. They are guaranteed to align well with your frame. $\endgroup$