# How to set a max value to barlegend in plots in general

I had a problem with interpolation in Density plot that was solved here

Now, I would like to set the value of the barlegend in the following DATA in a specific value.

DATA={{0., 0., 0.117237}, {0.125, 0.0721688, 0.0185109}, {0.125, 0.216506,
0.08128}, {0.25, 0., 0.08128}, {0.25, 0.288675, 0.0215464}, {0.25,
0.433013, 0.0978551}, {0.375, 0.0721688, 0.0215464}, {0.375,
0.216506, 0.0796793}, {0.375, 0.505181, 0.0215464}, {0.375,
0.649519, 0.08128}, {0.5, 0., 0.0978551}, {0.5, 0.433013,
0.0796793}, {0.5, 0.721688, 0.0185109}, {0.5, 0.866025,
0.117237}, {0.625, 0.0721688, 0.0215464}, {0.625, 0.216506,
0.0796793}, {0.625, 0.505181, 0.0215464}, {0.625, 0.649519,
0.08128}, {0.75, 0., 0.08128}, {0.75, 0.288675, 0.0215464}, {0.75,
0.433013, 0.0978551}, {0.875, 0.0721688, 0.0185109}, {0.875,
0.216506, 0.08128}, {1., 0., 0.117237}}


The max value in DATA z-axis is 0.117237, in which, the brightest spot in smoothhistogram correspond to this value. Lets suppose that I want to set the max value in BarLegend and for the brightest spot, for example, 0.20. How could I do this? Should I insert an imaginary set like, {x,y,0.20}, where x and y will set way far from the x,y points in DATA?

As mentinioned before, I'm using this to get the plot

wd = WeightedData[SetAccuracy[DATA[[All, ;; 2]],2], DATA[[All, -1]]];

SmoothDensityHistogram[wd, .05,
ColorFunction -> GrayLevel,
AspectRatio -> All,
PlotRange -> All,
Frame -> False]


Edit1: I want to compare two data sets DATA1 and DATA2, in which, each one has its respective maximum value, so I would like to set a BarLegend corresponding to maximum value in DATA1 (around 20) and see the corresponding brighter spot in DATA2 (around 0.07) less bright.

Legended[
SmoothDensityHistogram[wd, .05,
ColorFunction -> GrayLevel,
ColorFunctionScaling -> True,
AspectRatio -> All,
PlotRange -> All,
Frame -> False],
BarLegend[{"GrayTones", {0, 0.2}}]]


• I made an edit with other data sets because doing like your suggestion I cant see the difference in bright between a density plot with max value in 20, and a density plot with max value 0.07 setting this BarLegend with {0, 20}. Mar 2, 2022 at 17:26
• I think we need to set this max value in the SmoothDensityHistogram instead...So I'll move it to other Question, thanks for your help here. Mar 2, 2022 at 17:34
• Unless you turn off the ColorFunctionScaling, the arguments supplied to a color function are scaled to lie between 0 and 1. The min value maps to 0 and the max value maps to 1. The BarLegend above maps this range {0, 1} to {0, 0.2}. You will see more contrast if you change the ColorFunction, e,g., Legended[ SmoothDensityHistogram[wd, .05, ColorFunction -> (cf = "Rainbow"), ColorFunctionScaling -> True, AspectRatio -> All, PlotRange -> All, Frame -> False], BarLegend[{cf, {0, 0.2}}]] Mar 2, 2022 at 17:44
• Ok! There is any way to make this colorfunctionscaling correspond to a max value? With that, we could see darker points in DATA2 in the new post that I've made mathematica.stackexchange.com/questions/264539/… Mar 2, 2022 at 17:57
• Add to the BarLegend the option LegendLabel -> "whatever" Mar 2, 2022 at 19:33