I am having trouble making a custom range for a legend in ContourPlot
since the legend doesn't "talk" to the PlotRange
and adjust its scale accordingly. How do I go about fixing this?
As an explicit example consider the following. If I run ContourPlot
with an automatic legend I get the right scaling:
ContourPlot[x y , {x, 0, 2}, {y, 0, 2}, PlotLegends->Automatic,
ColorFunction ->"BlueGreenYellow"]
But if I use a custom legend range then the legend no longer corresponds to the image:
ContourPlot[x y , {x, 0, 2}, {y, 0, 2},
PlotLegends -> BarLegend[{"BlueGreenYellow", {0, 10}}]
How do I get the plot to use the same scale as the legend?