Can relative size changes be made to PointSize[], Thickness[] in mathematica?

拟墨画扇 提交于 2019-12-06 08:21:14

You can do this using the Style option form of PointSize with Inherited in the value:

Graphics[{Style[{Point[{0, 0}], 
Style[{Point[{.2, 0}], 
  Style[{Point[{.4, 0}], 
    Style[{Point[{.6, 0}], 
      Style[{Point[{.8, 0}]}, PointSize -> .9 Inherited]}, 
     PointSize -> .9 Inherited]}, PointSize -> .9 Inherited]}, 
 PointSize -> .9 Inherited]}, PointSize -> .1]}, PlotRange -> 1]

Those options that Mathematica keeps track of are revealed by AbsoluteOptions[] Try AbsoluteOptions[Graphics[{Point[{0, 0}]}]], for example. Unfortunately, PointSize is not among the options tracked.

So, why not simply use a variable to store the value to use?

ps = 0.01; Graphics[{PointSize[ps], 
  Table[Point[{RandomReal[], RandomReal[]}], {i, 100}]}]

Then...

Graphics[{PointSize[ps*2], 
  Table[Point[{RandomReal[], RandomReal[]}], {i, 100}]}]

I can't comment to Belisarius' "Directive" comments due to lack of points, so I chime in here:

Ragfield's code works, but all PointSize instructions are indeed marked red. Formatted as directives it still works and isn't marked as erroneous too:

Graphics[
 {
 Style[
  {
   Point[{0, 0}],
   Style[
    {
     Point[{.2, 0}],
     Style[
      {
       Point[{.4, 0}],
       Style[
        {
         Point[{.6, 0}],
         Style[
          {
           Point[{.8, 0}]
          },
          PointSize[.9 Inherited]
         ]
        },
        PointSize[.9 Inherited]
       ]
      },
      PointSize[.9 Inherited]
     ]
    },
    PointSize[.9 Inherited]
   ]
  },
  PointSize[.1]
 ]
},
PlotRange -> 1
]

I like a bit of formatting for deeply nested structures like this. Anyone know how you can paste formatted Mma code in Stackoverflow without having to do manual formatting afterwards?

Nice to hear about Inherited BTW. Apparently new since v6, but it flew under my radar.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!