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

喜夏-厌秋 提交于 2020-01-02 13:51:13

问题


Arising from this question regarding line thickness and point size setting [e.g. PointSize[Large}, PointSize[0.5]), I was wondering if it is feasible to change PointSize[], Thickness[] etc in a relative manner?

I.e. why is it that PointSize[Larger] doesn't work? Or is possible to somehow query the existing pointsize and perhaps do something likePointSize[1.25*GetPointSize[]] (I haven't been able to figure this out if something like "GetPointSize[]" exists, neither with a quick look at the documentation, nor from a quick reverse-engineering look at PointSize[x])


回答1:


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]




回答2:


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}]}]




回答3:


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.



来源:https://stackoverflow.com/questions/5174250/can-relative-size-changes-be-made-to-pointsize-thickness-in-mathematica

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