操纵:间距和背景

时间:2011-10-23 01:01:28

标签: wolfram-mathematica

请考虑:

 Manipulate[Rasterize[Graphics[{
    Black, Rectangle[{0, 0}, {6, 10}],
    Red, Rectangle[{0, 0}, {2, L}],
    Green, Rectangle[{2, 0}, {4, M}],
    Blue, Rectangle[{4, 0}, {6, S}]},
    ImageSize -> {200, 270},
    ImageSize -> 50]],
    Control@{{L, 1, Style["L", Red, Bold, 24]}, Range[10], 
    ControlType -> Slider, ControlPlacement -> Top, 
    DefaultBaseStyle -> {Bold, 16, FontFamily -> "Helvetica"}, 
    Appearance -> "Labeled", ImageSize -> 200},
    Control@{{M, 1, Style["M", Green, Bold, 24]}, Range[10], 
    ControlType -> Slider, ControlPlacement -> Top, 
    DefaultBaseStyle -> {Bold, 16, FontFamily -> "Helvetica"}, 
    Appearance -> "Labeled", ImageSize -> 200},
    Control@{{S, 1, Style["S", Blue, Bold, 24]}, Range[10], 
    ControlType -> Slider, ControlPlacement -> Top, 
    DefaultBaseStyle -> {Bold, 16, FontFamily -> "Helvetica"}, 
    Appearance -> "Labeled", ImageSize -> 200}]

enter image description here

  • 我可以更改背景颜色:黑色而不是白色。

  • 为什么右边有这么多空白空间。我从来没有能够将滑块大小与Manipulate的宽度相匹配,只是包含所包含的图形?

2 个答案:

答案 0 :(得分:5)

如果您在Paneled -> False中设置Manipulate,则会缩小Graphics周围的空白区域。通过在Graphics[...]命令中正确设置,可以轻松地将剩余的白色设置为具有不同的背景。您还可以通过在BaseStyle Manipulate中设置背景来设置外部面板的样式。以下是对代码的略微修改:

Manipulate[
 Graphics[{Black, Rectangle[{0, 0}, {6, 10}], Red, 
   Rectangle[{0, 0}, {2, L}], Green, Rectangle[{2, 0}, {4, M}], Blue, 
   Rectangle[{4, 0}, {6, S}]}, ImageSize -> {200, 300}, 
  Background -> LightOrange], 
 Control@{{L, 1, Style["L", Red, Bold, 24]}, Range[10], 
   ControlType -> Slider, ImageSize -> Small, ControlPlacement -> Top,
    DefaultBaseStyle -> {Bold, 16, FontFamily -> "Helvetica"}, 
   Appearance -> "Labeled"}, 
 Control@{{M, 1, Style["M", Green, Bold, 24]}, Range[10], 
   ControlType -> Slider, ImageSize -> Small, ControlPlacement -> Top,
    DefaultBaseStyle -> {Bold, 16, FontFamily -> "Helvetica"}, 
   Appearance -> "Labeled"}, 
 Control@{{S, 1, Style["S", Blue, Bold, 24]}, Range[10], 
   ControlType -> Slider, ImageSize -> Small, ControlPlacement -> Top,
    DefaultBaseStyle -> {Bold, 16, FontFamily -> "Helvetica"}, 
   Appearance -> "Labeled"}, BaseStyle -> {Background -> LightPurple},
  Paneled -> False, ImageMargins -> 10]

enter image description here

我之前的例子中没有注意到标签已经略微向上移动了。在任何情况下,belisarius使用ImageSize -> Small的建议都比较简单,所以我采用了它。

答案 1 :(得分:3)

我认为你过度使用了ImageSize选项:

Manipulate[
 Graphics[{Black, Rectangle[{0, 0}, {6, 10}], Red, 
   Rectangle[{0, 0}, {2, L}], Green, Rectangle[{2, 0}, {4, M}], Blue, 
   Rectangle[{4, 0}, {6, S}]}, ImageSize -> {200, 300}],

 Control@{{L, 1, Style["L", Red, Bold, 24]}, Range[10], 
   ControlType -> Slider, ImageSize -> Small, ControlPlacement -> Top,
    DefaultBaseStyle -> {Bold, 16, FontFamily -> "Helvetica"}, 
   Appearance -> "Labeled"}, 
 Control@{{M, 1, Style["M", Green, Bold, 24]}, Range[10], 
   ControlType -> Slider, ImageSize -> Small, ControlPlacement -> Top,
    DefaultBaseStyle -> {Bold, 16, FontFamily -> "Helvetica"}, 
   Appearance -> "Labeled"}, 
 Control@{{S, 1, Style["S", Blue, Bold, 24]}, Range[10], 
   ControlType -> Slider, ImageSize -> Small, ControlPlacement -> Top,
    DefaultBaseStyle -> {Bold, 16, FontFamily -> "Helvetica"}, 
   Appearance -> "Labeled"}]

enter image description here