匹配图例和绘图大小

时间:2011-10-16 19:39:10

标签: wolfram-mathematica plot mathematica-8

请考虑:

intense = Reverse[Round[Rationalize /@ N[10^Range[0, 3, 1/3]]]];
values = Range[0, 9/10, 1/10];

intensityLegend = Column[Prepend[MapThread[
                         Function[{intensity, values},
                         Row[{Graphics[{(Lighter[Blue, values]),
                         Rectangle[{0, 0}, {4, 1}], Black, 
                         Text[Style[ToString[intensity], 16, Bold], {2, .5}]}]}]],
                        {intense, values}], Text[Style["Photons Number", Bold, 15]]]];

IntersectionDp1={{1., 588.377}, {2.15443, 580.306}, {4.64159, 573.466}, {10.,560.664}, 
                 {21.5443, 552.031}, {46.4159, 547.57}, {100.,545.051}, 
                 {215.443, 543.578}, {464.159, 542.281}, {1000., 541.346}}


FindD1=ListLogLinearPlot[Map[List, IntersectionDp1], 
                  Frame -> True, 
                  AxesOrigin -> {-1, 0}, 
                  PlotMarkers -> 
                  With[{markerSize = 0.04}, {Graphics[{Lighter[Blue, #], Disk[]}], 
                       markerSize} & /@Range[9/10, 0, -1/10]], Filling -> Axis, 
                  FillingStyle -> Opacity[0.8], 
                  PlotRange -> {{.5, 1100}, {540, 600}},
                  ImageSize->400];

Grid[{{intensityLegend, FindD1}, {intensityLegend, FindD1}}, 
      ItemSize -> {50, 20}, Frame -> True]

enter image description here

如何才能获得图例列大小以适应绘图区域的高度?

当Row调整大小时我需要使用Grid。这就是我在网格中重复的原因。

2 个答案:

答案 0 :(得分:9)

使用图像尺寸。 (*< - *)标志着对代码的重要修改,其余主要是字体大小的东西:

intense = Reverse[Round[Rationalize /@ N[10^Range[0, 3, 1/3]]]];
values = Range[0, 9/10, 1/10];
imgSize = 400;                                                          (* <- *) 
Off[Ticks::ticks]

IntersectionDp1 =  {{1., 588.377},     {2.15443, 580.306}, {4.64159, 573.466}, 
   {10., 560.664}, {21.5443, 552.031}, {46.4159, 547.57},  {100., 545.051},
   {215.443, 543.578}, {464.159, 542.281}, {1000., 541.346}}

FindD1 = ListLogLinearPlot[Map[List, IntersectionDp1], Frame -> True, 
   AxesOrigin -> {-1, 0}, 
   PlotMarkers -> 
    With[{markerSize = 0.04}, 
     {Graphics[{Lighter[Blue, #], Disk[]}], markerSize} & 
       /@ Range[9/10, 0, -1/10]], Filling -> Axis, FillingStyle -> Opacity[0.8], 
       PlotRange -> {{.5, 1100}, {540, 600}}, ImageSize -> imgSize];    (* <- *) 

intensityLegend =
  Rasterize[Column[
    Prepend[
     Reverse@MapThread[                                                 (* <- *) 
      Function[{intensity, values}, 
       Row[{Graphics[{(Lighter[Blue, values]), 
           Rectangle[{0, 0}, {4, 1}], Black, 
           Text[Style[ToString[intensity], 30, Bold], {2, .5}]}]}]],
      {intense, values}],
     Text[Style["Photons Number", Bold, 25]]]], 
   ImageSize -> {Automatic,                                             (* <- *) 
     IntegerPart@                            
      First[imgSize Cases[AbsoluteOptions[FindD1], 
         HoldPattern[AspectRatio -> x_] -> x]]}];

Grid[{{intensityLegend, FindD1}, {intensityLegend, FindD1}}, Frame -> True]

enter image description here

我为了审美目的而颠倒了强度栏。

修改

如果您没有为Plot明确指定ImageSize选项,则会令人失望地发现AbsoluteOptions[Plot, "ImageSize"]返回"Automatic"

编辑回答@ 500的评论

表达式:

   ImageSize -> {Automatic,                                             (* <- *) 
     IntegerPart@                            
      First[imgSize Cases[AbsoluteOptions[FindD1], 
         HoldPattern[AspectRatio -> x_] -> x]]}];

实际上是应该工作以获取绘图的图像大小的替代品:

   ImageSize -> {Automatic, Last@AbsoluteOptions[FindD1,"ImageSize"]}   

那么,IntegerPart[...]正在做的是获取绘图图像的垂直尺寸,将imgSize乘以绘图的AspectRatio。 要了解它的工作原理,请运行代码,然后键入:

AbsoluteOptions[FindD1] 

你会在那里看到Plot选项。 Cases []函数只是提取AspectRatio选项。

事实上,有一种更简洁的方法可以完成Cases []所做的事情。它是:

AbsoluteOptions[FindD1,"AspectRatio"] 

但是AbsoluteOptions函数中还有一个错误阻止我们以这种方式使用它。

答案 1 :(得分:4)

如何让传奇变得更小?

intensityLegend = 
  Column[Prepend[
    MapThread[
     Function[{intensity, values}, 
      Row[{Graphics[{(Lighter[Blue, values]), 
          Rectangle[{0, 0}, {4, 1}], Black, 
          Text[Style[ToString[intensity], 12, Bold], {2, .5}]}, 
         ImageSize -> 50]}]], {intense, values}], 
    Text[Style["Photons Number", Bold, 15]]]];

enter image description here