5
$\begingroup$

Is it possible to edit the options of an object like Plot or Graphics after I store it as a variable?

For example, consider the following Voronoi mesh

VoronoiMesh[RandomReal[1, {5, 2}],
 ImageSize -> Medium,
 Epilog -> 
  Inset[Framed[Column[{BarLegend["Rainbow"]}, Alignment -> Center], 
    Background -> White], {Right, Bottom}, {Right, Bottom}]]

enter image description here

Now, if I set

mesh = VoronoiMesh[RandomReal[1, {5, 2}]];

My goal is to "edit" the object mesh and include the two options for ImageSize and Epilog

ImageSize -> Medium,
Epilog -> 
 Inset[Framed[Column[{BarLegend["Rainbow"]}, Alignment -> Center], 
   Background -> White], {Right, Bottom}, {Right, Bottom}]

I have tried something with SetOptions and SetProperty, but nothing seems to work. Something like

SetOptions[mesh,
 ImageSize -> Medium,
 Epilog -> 
  Inset[Framed[Column[{BarLegend["Rainbow"]}, Alignment -> Center], 
    Background -> White], {Right, Bottom}, {Right, Bottom}]]

Any ideas?

$\endgroup$
5
$\begingroup$

Since the output of VoronoiMesh is a MeshRegion, use MeshRegion to change options. An example mesh:

SeedRandom[1]
mesh = VoronoiMesh[RandomReal[1, {5, 2}]]

enter image description here

Using MeshRegion to change options:

MeshRegion[mesh,
    ImageSize -> Medium,
    Epilog -> Inset[
        Framed[Column[{BarLegend["Rainbow"]},Alignment->Center],Background->White],
        {Right,Bottom},
        {Right,Bottom}
    ]
]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you! This is great. What about Graphics or Plot? Can something similar be used? $\endgroup$ – sam wolfe Jan 6 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.