我在画密度图的时候,想让我的图例随着主图像的大小自动改变,让它们两个保持一致。下面是我手动设置的大小
p1 = DensityPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3},
ColorFunction -> ColorData["RedBlueTones"], ImageSize -> Large,
PlotLegends ->
Placed[BarLegend[Automatic, LegendMarkerSize -> {40, 530}], {After,
Top}], FrameStyle -> Directive[Bold, 28, FontFamily -> "Times"],
FrameLabel -> {"\!\(\*SubscriptBox[\(k\), \(x\)]\)",
"\!\(\*SubscriptBox[\(k\), \(y\)]\)"},
PlotRange -> {{-4, 4}, {-3, 3}}]
结果是这样的

在这里我是通过
LegendMarkerSize -> {40, 530}
手动设置了图例大小。
还有一个问题,如果我想将这个图例放置到图像的上端又该怎么调整。虽然这里我用了Placed,但是我发现设置成
PlotLegends ->
Placed[BarLegend[Automatic, LegendMarkerSize -> {40, 530}], {After,
Top}]
但是我始终没办法将这个图例改变到上端。