1
$\begingroup$

I want to put two ListDensityPlot together using "Style" command, but I don't how to control the size of the plot to make it the same height of the legend. The following the is code

p = ListDensityPlot[Table[Sin[i + j^2], {i, 0, 3, 0.05}, {j, 0, 3, 0.05}], ColorFunction ->"SolarColors", PlotLegends -> Automatic]
Style[Grid[{{"Title", SpanFromLeft}, {p, p}}, Spacings -> 0, ItemStyle -> Directive[FontFamily -> "CMU Serif", FontSize -> 40]], LineBreakWithin -> False]

The figure I want is

enter image description here

After I run the code kglr mention and set "LegendMarkerSize -> {Automatic, 500}"

ListDensityPlot[Table[Sin[i + j^2], {i, 0, 3, 0.05}, {j, 0, 3, 0.05}], ColorFunction -> "SolarColors", ImageSize -> {200, 200}, PlotLegends ->  BarLegend[Automatic, LegendMarkerSize -> {Automatic, 500}]]

But it doesn't change the legend size.

enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$

Use the option ImageSize in ListDensityPlot and the option LegendMarkerSize in BarLegend with the same value for vertical size:

ListDensityPlot[Table[Sin[i + j^2], {i, 0, 3, 0.05}, {j, 0, 3, 0.05}],
  ColorFunction -> "SolarColors", ImageSize -> {200, 200}, 
 PlotLegends -> BarLegend[Automatic, LegendMarkerSize -> {Automatic, 200}]]

enter image description here

Use ImageSize -> {360, 360} and LegendMarkerSize -> {Automatic, 360} to get

enter image description here

Using ImageSize -> Automatic and LegendMarkerSize -> {Automatic, 360} gives the same picture.

$\endgroup$
4
  • $\begingroup$ Thank you so much! $\endgroup$
    – JieJiang
    Dec 13, 2020 at 11:59
  • $\begingroup$ I run the code you mention and set "LegendMarkerSize -> {Automatic, 500}", but it doesn't work, my Mathematica's version is 12.0.0.0. I have edit my question and show the picture there. $\endgroup$
    – JieJiang
    Dec 13, 2020 at 12:25
  • $\begingroup$ @JieJiang, in version 12.2.0, use LegendMarkerSize -> {15,500} . $\endgroup$
    – kglr
    Dec 13, 2020 at 12:33
  • $\begingroup$ OK I see. Thank you again! $\endgroup$
    – JieJiang
    Dec 13, 2020 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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