2011-10-16 19 views
4

請考慮:匹配傳說和地塊大小

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

我怎麼能得到傳說列大小以適合繪圖區域的高度?

雖然行調整大小,我需要使用網格。這就是我在網格中複製的原因。

回答

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[ 
    [email protected][             (* <- *) 
     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,            (* <- *) 
    [email protected]        
     First[imgSize Cases[AbsoluteOptions[FindD1], 
     HoldPattern[AspectRatio -> x_] -> x]]}]; 

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

enter image description here

哪裏轉回美觀的目的強度列。

編輯

如果你沒有明確指定的情節IMAGESIZE選項,你會失望的發現,AbsoluteOptions[Plot, "ImageSize"]回報"Automatic"

編輯接聽波紋管

表達了@ 500的評論:

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

是一個真正的工作更換的東西,應該工作但不得到的圖像尺寸圖:

ImageSize -> {Automatic, [email protected][FindD1,"ImageSize"]} 

因此,IntegerPart[...]事情正在做的是獲得繪圖圖像的垂直尺寸,將imgSize乘以繪圖的AspectRatio
要了解它是如何工作的,運行代碼,然後鍵入:

AbsoluteOptions[FindD1] 

,你會看到繪圖選項那裏。然後Cases []功能只是提取AspectRatio選項。

事實上,有一種更簡潔的方法來完成Cases []所做的事情。它是:

AbsoluteOptions[FindD1,"AspectRatio"] 

但在AbsoluteOptions函數中有另一個錯誤,它阻止我們以這種方式使用它。

+0

該死的我只是把它翻了!這看起來很好!謝謝 !!! – 500

+0

你能解釋下面的部分嗎?我認爲它有條件地將圖例的y大小調整爲情節本身,但我不理解這部分:IntegerPart @ 第一個[imgSize個案[AbsoluteOptions [FindD1], HoldPattern [AspectRatio - > x_] - > x]] – 500

+0

@ 500請參閱編輯 –

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

+0

非常感謝!但我必須承認,我無法掌握單位或縮放比例:-)所以它仍然是魔術。我希望我們總是在所有情況下談論像素! – 500