1
$\begingroup$

Is there a way to make the barlegend in a density or contour plot the same width/ height as the plot, depending on if you position the barlegend above or after the plot? The only related post that I found was this one here, and it is over 5 years old.

$\endgroup$
1

1 Answer 1

2
$\begingroup$
  DensityPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3}, 
 ImageSize -> {300, 300}, 
 PlotLegends -> BarLegend[Automatic, LegendMarkerSize -> {100, 300}]] 

enter image description here

 DensityPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3}, 
     ImageSize -> {300, 300}, 
     PlotLegends -> BarLegend[Automatic, LegendMarkerSize -> {300, 300}]]

enter image description here

Edit:

DensityPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3}, 
 ImageSize -> {300, 300}, 
 PlotLegends -> 
  Placed[BarLegend[Automatic, LegendLayout -> "Row", 
    LegendMarkerSize -> {300, 100}], Above]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Btw, do you know if it is possible to change the appearance of the legend, as you did, and have it placed above the plot? $\endgroup$ Mar 2, 2018 at 8:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.