3
$\begingroup$

Is there any way to get the '%' in the BarLegend to be black instead of light gray?

ContourPlot[x^2 + y^2, {x, -10, 10}, {y, -10, 10}, 
PlotLegends -> BarLegend[Automatic, LegendFunction -> "Panel",
   LabelStyle -> {FontFamily -> "Monaco", FontSize -> 18, 
   FontColor -> Black}],
FrameStyle -> Black,
TargetUnits -> "%"]

ContourPlot with barLegend and Units (in different style)

$\endgroup$
4
$\begingroup$
cp = ContourPlot[x^2 + y^2, {x, -10, 10}, {y, -10, 10},
 PlotLegends -> BarLegend[Automatic, LegendFunction -> "Panel",
 LabelStyle -> {FontFamily -> "Monaco", FontSize -> 18,
 FontColor -> Black}], FrameStyle -> Black, TargetUnits -> "%"]

Mathematica graphics

FullForm[cp[[2,1]]] gives the code that constructs the legend. Inspecting that code we find the piece that we need to modify:

Rule[Charting`TickAnnotations, Style[QuantityForm["Percent", "PlotLabel"], GrayLevel[0.7`]]]

So using the following replacement rule

graytoblack = Rule[Charting`TickAnnotations, Style[q_,GrayLevel[_]]]:>
    Rule[Charting`TickAnnotations,   Style[q,GrayLevel[0]]];

to post-process cp

cp/.graytoblack

we get:

Mathematica graphics

$\endgroup$
  • $\begingroup$ You could have used the simpler cp /. GrayLevel[0.7`]->GrayLevel[0]; but this would have changed all GrayLevel[0.7`] elements, not just the "%" in the legend. $\endgroup$ – kglr Mar 1 '16 at 4:46

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.