I am looking for a way to plot e.g. a legended DensityPlot
with a BarLegend
, where the colorbar shows two differently scaled ticks and labels. Take the following example:
or take a look at the folloowing example from Python/matplotlib: https://stackoverflow.com/questions/27151098/draw-colorbar-with-twin-scales.
Idealy I would like to provide a scaling relation to to apply to the data values in order to get the second scale.
I was hoping that there is already some hidden functionality in place, But I couldn't coerce "Charting'TickSide"
to allow for other arguments than Left
or Right
. After some fiddling around I could at least convince Mathematica to plot two BarLegends
and hacked Column
for a partial overlap (the -2 spacing argument). I also tried to fiddle around with the InputForm
but the BarLegend
is not converted to Graphics
primitives. But that is as far as I got.
Legended[
MatrixPlot[
Table[i*j, {i, 1, 10}, {j, 1, 10}],
ColorFunction -> (ColorData["SolarColors"][Rescale[#, {1, 100}]] &),
ColorFunctionScaling -> False],
Placed[
Column[{
BarLegend[{"SolarColors", {1, 100}},
LegendMarkerSize -> 300,
Charting`TickSide -> Left,
LegendLabel -> "\[Degree]F",
LegendLayout -> "Row"],
BarLegend[{"SolarColors", {1, 100}},
LegendMarkerSize -> 300,
Charting`TickSide -> Right,
LegendLabel -> Placed["\[Degree]C", Below],
LegendLayout -> "Row"]},
Automatic, -2],
Below]
]
Interesting remark: the quotation marks aropund the °C in the lower LegendLabel
("°C") only appear in the jpg, not on the screen in the notebook ouotput.