问题
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