This is a problem of Legends in density plot. As pointed out by this post. Generally we want to same height of legend bar and plot.
The code for the basic case is
ContourPlot[Sin[x y], {x, 0, 3 \[Pi]}, {y, 0, \[Pi]},
PlotLegends -> Automatic, ImageSize -> {Automatic, 100}]
Now I want to compare 4 cases
The first two case is OK. First one specify horizontal width ImageSize->100
; second one specify vertical height ImageSize->{Automatic, 100}
But sometimes we want accurate aspect ratio. However, the third one with AspectRatio->Automatic
is totally wrong. But we can see the legend bar is exactly the same, it conform with horizontal width, thought it should be confirm with image height!!
The fourth one as suggested by xslittlegrass is a fix for third one. Give right ascpet ratio, and at the same time want to get a legend bar of right height. One thing to note is that, I have intentionaly choose AspecRatio->1/3, ImageSize->300
, and you can see again the bar is exactly the same as previous three plots. That is 300/3=100, this number is what PlotLegend conforms with. However, suprisely, the height is still not exactly right, as pointed out by red lines in the image. I don't know what is wrong?
So finally, my question is: How to make PlotLegend the same height as Plot which is specified with horizontal image width? (Constrain horizontal width of each plot is useful when we have multi plot in a row)