How to scale and shift the coordinates of a Graphics object?Why does show combined plots and graphics fail in CDF Player but not in Mathematica?Opacity function applied to Graphics ObjectsHow to make Inset graphics maintain relative sizes when combinedinset legend from top right corner / find size of swatchlegend bounding boxMove Graphics ObjectColor coded bar to represent numeric valuesStep plot with log-log scaleHow to superimpose plots and graphics in the same coordinate system?Inset 3D graphics without croppingHow can I vary the height of items in a GraphicsColumn?
Looking for an old image of designing a cpu with plan laid out / being edited on a literal floor
Could a guilty Boris Johnson be used to cancel Brexit?
What should I do about a religious player who refuses to accept the existence of multiple gods in D&D?
arcpy.GetParameterAsText not passing arguments to script?
Accidentally cashed a check twice
Working in the USA for living expenses only; allowed on VWP?
Creating Fictional Slavic Place Names
Can an old DSLR be upgraded to match modern smartphone image quality
Is there a rule that prohibits us from using 2 possessives in a row?
How can I offer a test ride while selling a bike?
How do I truncate a csv file?
Asking bank to reduce APR instead of increasing credit limit
Have powerful mythological heroes ever run away or been deeply afraid?
Does a component pouch automatically contain components?
Are academic associations obliged to comply with the US government?
Estimate related to the Möbius function
Why does the UK have more political parties than the US?
Is there a way to save this session?
Order by does not work as I expect
What is the most important characteristic of New Weird as a genre?
What does War Machine's "Canopy! Canopy!" line mean in "Avengers: Endgame"?
Opposite of "Squeaky wheel gets the grease"
Why is Colorado so different politically from nearby states?
Orientable with respect to complex cobordism?
How to scale and shift the coordinates of a Graphics object?
Why does show combined plots and graphics fail in CDF Player but not in Mathematica?Opacity function applied to Graphics ObjectsHow to make Inset graphics maintain relative sizes when combinedinset legend from top right corner / find size of swatchlegend bounding boxMove Graphics ObjectColor coded bar to represent numeric valuesStep plot with log-log scaleHow to superimpose plots and graphics in the same coordinate system?Inset 3D graphics without croppingHow can I vary the height of items in a GraphicsColumn?
$begingroup$
I am trying to overlap two Graphics
objects g1
and g2
with Show
. However, I found that when the coordinates of each object is defined to quite different ranges, I need to "scale" and "shift" the coordinates of one object to get the desired look.
For example,
g1 = Graphics[GrayLevel[0.8], Rectangle[-2, -2, 2, 2]];
g2 = Graphics[GrayLevel[0.5], Rectangle[0, 0, 1, 1]];
Show[g1, AspectRatio -> 1, Axes -> True, ImageSize -> 230]
Show[g2, AspectRatio -> 1, Axes -> True, ImageSize -> 230]
Show[g1, g2, AspectRatio -> 1, Axes -> True, ImageSize -> 230]
The overlapped version of g1
and g2
looks like this
However, I would like to scale the coordinates of g2
to make g2
twice large and also shift its coordinates so the center can "roughly" coincide the center of g1
. I say "roughly" because g1
and g2
may be some graphics not of a regular shape. The desired result will look like
So how can I manipulate the coordinates of g2
to adjust its relative position and size when Show
with g1
? Please avoid modifying the definition of g1
and g2
as they can be any Graphics
copy-pasted over.
graphics coordinate
$endgroup$
add a comment |
$begingroup$
I am trying to overlap two Graphics
objects g1
and g2
with Show
. However, I found that when the coordinates of each object is defined to quite different ranges, I need to "scale" and "shift" the coordinates of one object to get the desired look.
For example,
g1 = Graphics[GrayLevel[0.8], Rectangle[-2, -2, 2, 2]];
g2 = Graphics[GrayLevel[0.5], Rectangle[0, 0, 1, 1]];
Show[g1, AspectRatio -> 1, Axes -> True, ImageSize -> 230]
Show[g2, AspectRatio -> 1, Axes -> True, ImageSize -> 230]
Show[g1, g2, AspectRatio -> 1, Axes -> True, ImageSize -> 230]
The overlapped version of g1
and g2
looks like this
However, I would like to scale the coordinates of g2
to make g2
twice large and also shift its coordinates so the center can "roughly" coincide the center of g1
. I say "roughly" because g1
and g2
may be some graphics not of a regular shape. The desired result will look like
So how can I manipulate the coordinates of g2
to adjust its relative position and size when Show
with g1
? Please avoid modifying the definition of g1
and g2
as they can be any Graphics
copy-pasted over.
graphics coordinate
$endgroup$
add a comment |
$begingroup$
I am trying to overlap two Graphics
objects g1
and g2
with Show
. However, I found that when the coordinates of each object is defined to quite different ranges, I need to "scale" and "shift" the coordinates of one object to get the desired look.
For example,
g1 = Graphics[GrayLevel[0.8], Rectangle[-2, -2, 2, 2]];
g2 = Graphics[GrayLevel[0.5], Rectangle[0, 0, 1, 1]];
Show[g1, AspectRatio -> 1, Axes -> True, ImageSize -> 230]
Show[g2, AspectRatio -> 1, Axes -> True, ImageSize -> 230]
Show[g1, g2, AspectRatio -> 1, Axes -> True, ImageSize -> 230]
The overlapped version of g1
and g2
looks like this
However, I would like to scale the coordinates of g2
to make g2
twice large and also shift its coordinates so the center can "roughly" coincide the center of g1
. I say "roughly" because g1
and g2
may be some graphics not of a regular shape. The desired result will look like
So how can I manipulate the coordinates of g2
to adjust its relative position and size when Show
with g1
? Please avoid modifying the definition of g1
and g2
as they can be any Graphics
copy-pasted over.
graphics coordinate
$endgroup$
I am trying to overlap two Graphics
objects g1
and g2
with Show
. However, I found that when the coordinates of each object is defined to quite different ranges, I need to "scale" and "shift" the coordinates of one object to get the desired look.
For example,
g1 = Graphics[GrayLevel[0.8], Rectangle[-2, -2, 2, 2]];
g2 = Graphics[GrayLevel[0.5], Rectangle[0, 0, 1, 1]];
Show[g1, AspectRatio -> 1, Axes -> True, ImageSize -> 230]
Show[g2, AspectRatio -> 1, Axes -> True, ImageSize -> 230]
Show[g1, g2, AspectRatio -> 1, Axes -> True, ImageSize -> 230]
The overlapped version of g1
and g2
looks like this
However, I would like to scale the coordinates of g2
to make g2
twice large and also shift its coordinates so the center can "roughly" coincide the center of g1
. I say "roughly" because g1
and g2
may be some graphics not of a regular shape. The desired result will look like
So how can I manipulate the coordinates of g2
to adjust its relative position and size when Show
with g1
? Please avoid modifying the definition of g1
and g2
as they can be any Graphics
copy-pasted over.
graphics coordinate
graphics coordinate
asked May 16 at 19:38
nanjunnanjun
50229
50229
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
You can use Scale
on First @ g2
(which contains the graphics directives and primitives):
Show[g1, Graphics @ Scale[First @ g2, 2, 1, 1], AspectRatio -> 1,
Axes -> True, ImageSize -> 230]
Alterantively, you can use combination of Scale
and Translate
:
Show[g1, Graphics @ Translate[Scale[First @ g2, 2], -1, 1/2],
AspectRatio -> 1, Axes -> True, ImageSize -> 230]
or
Show[g1, Graphics@Translate[Scale[First@g2, 2, 0, 0], -1, 1],
AspectRatio -> 1, Axes -> True, ImageSize -> 230]
same picture
$endgroup$
$begingroup$
Thanks @kglr for the answer. Could you explain how the second argument ofTranslate
is determined? Why it is-1, 1/2
instead of-1, 1
?
$endgroup$
– nanjun
May 16 at 20:07
1
$begingroup$
@nanjun, if you useScale[First@g2, 2, 0, 0]
(with the third argument specifying the point that is kept fixed) you can use-1,1
instead of-1,1/2
) , that is, you can useShow[g1, Graphics@Translate[Scale[First@g2, 2, 0, 0], -1, 1], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
$endgroup$
– kglr
May 16 at 20:33
1
$begingroup$
... sinceScale[First@g2, 2]
fixes the center (1/2,1/2
) the origin of the rectangle is already shifted by-1/2,1/2
beforeTranslate
is applied. (CompareShow[g1, Graphics@Scale[First@g2, 2], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
andShow[g1, Graphics@Scale[First@g2, 2, 0,0], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
$endgroup$
– kglr
May 16 at 20:37
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
May 16 at 20:44
add a comment |
$begingroup$
I'm not saying that this is what you need for your problem, but sometimes when you want to superimpose graphics like this, you're looking for Inset
:
Show[
g1,
Graphics@Inset[
Show[g2, PlotRangePadding -> 0],
0, 0, Center, Center, 2, 2
],
Axes -> True, ImageSize -> 230
]
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f198521%2fhow-to-scale-and-shift-the-coordinates-of-a-graphics-object%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
You can use Scale
on First @ g2
(which contains the graphics directives and primitives):
Show[g1, Graphics @ Scale[First @ g2, 2, 1, 1], AspectRatio -> 1,
Axes -> True, ImageSize -> 230]
Alterantively, you can use combination of Scale
and Translate
:
Show[g1, Graphics @ Translate[Scale[First @ g2, 2], -1, 1/2],
AspectRatio -> 1, Axes -> True, ImageSize -> 230]
or
Show[g1, Graphics@Translate[Scale[First@g2, 2, 0, 0], -1, 1],
AspectRatio -> 1, Axes -> True, ImageSize -> 230]
same picture
$endgroup$
$begingroup$
Thanks @kglr for the answer. Could you explain how the second argument ofTranslate
is determined? Why it is-1, 1/2
instead of-1, 1
?
$endgroup$
– nanjun
May 16 at 20:07
1
$begingroup$
@nanjun, if you useScale[First@g2, 2, 0, 0]
(with the third argument specifying the point that is kept fixed) you can use-1,1
instead of-1,1/2
) , that is, you can useShow[g1, Graphics@Translate[Scale[First@g2, 2, 0, 0], -1, 1], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
$endgroup$
– kglr
May 16 at 20:33
1
$begingroup$
... sinceScale[First@g2, 2]
fixes the center (1/2,1/2
) the origin of the rectangle is already shifted by-1/2,1/2
beforeTranslate
is applied. (CompareShow[g1, Graphics@Scale[First@g2, 2], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
andShow[g1, Graphics@Scale[First@g2, 2, 0,0], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
$endgroup$
– kglr
May 16 at 20:37
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
May 16 at 20:44
add a comment |
$begingroup$
You can use Scale
on First @ g2
(which contains the graphics directives and primitives):
Show[g1, Graphics @ Scale[First @ g2, 2, 1, 1], AspectRatio -> 1,
Axes -> True, ImageSize -> 230]
Alterantively, you can use combination of Scale
and Translate
:
Show[g1, Graphics @ Translate[Scale[First @ g2, 2], -1, 1/2],
AspectRatio -> 1, Axes -> True, ImageSize -> 230]
or
Show[g1, Graphics@Translate[Scale[First@g2, 2, 0, 0], -1, 1],
AspectRatio -> 1, Axes -> True, ImageSize -> 230]
same picture
$endgroup$
$begingroup$
Thanks @kglr for the answer. Could you explain how the second argument ofTranslate
is determined? Why it is-1, 1/2
instead of-1, 1
?
$endgroup$
– nanjun
May 16 at 20:07
1
$begingroup$
@nanjun, if you useScale[First@g2, 2, 0, 0]
(with the third argument specifying the point that is kept fixed) you can use-1,1
instead of-1,1/2
) , that is, you can useShow[g1, Graphics@Translate[Scale[First@g2, 2, 0, 0], -1, 1], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
$endgroup$
– kglr
May 16 at 20:33
1
$begingroup$
... sinceScale[First@g2, 2]
fixes the center (1/2,1/2
) the origin of the rectangle is already shifted by-1/2,1/2
beforeTranslate
is applied. (CompareShow[g1, Graphics@Scale[First@g2, 2], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
andShow[g1, Graphics@Scale[First@g2, 2, 0,0], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
$endgroup$
– kglr
May 16 at 20:37
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
May 16 at 20:44
add a comment |
$begingroup$
You can use Scale
on First @ g2
(which contains the graphics directives and primitives):
Show[g1, Graphics @ Scale[First @ g2, 2, 1, 1], AspectRatio -> 1,
Axes -> True, ImageSize -> 230]
Alterantively, you can use combination of Scale
and Translate
:
Show[g1, Graphics @ Translate[Scale[First @ g2, 2], -1, 1/2],
AspectRatio -> 1, Axes -> True, ImageSize -> 230]
or
Show[g1, Graphics@Translate[Scale[First@g2, 2, 0, 0], -1, 1],
AspectRatio -> 1, Axes -> True, ImageSize -> 230]
same picture
$endgroup$
You can use Scale
on First @ g2
(which contains the graphics directives and primitives):
Show[g1, Graphics @ Scale[First @ g2, 2, 1, 1], AspectRatio -> 1,
Axes -> True, ImageSize -> 230]
Alterantively, you can use combination of Scale
and Translate
:
Show[g1, Graphics @ Translate[Scale[First @ g2, 2], -1, 1/2],
AspectRatio -> 1, Axes -> True, ImageSize -> 230]
or
Show[g1, Graphics@Translate[Scale[First@g2, 2, 0, 0], -1, 1],
AspectRatio -> 1, Axes -> True, ImageSize -> 230]
same picture
edited May 17 at 3:57
answered May 16 at 19:48
kglrkglr
195k10216439
195k10216439
$begingroup$
Thanks @kglr for the answer. Could you explain how the second argument ofTranslate
is determined? Why it is-1, 1/2
instead of-1, 1
?
$endgroup$
– nanjun
May 16 at 20:07
1
$begingroup$
@nanjun, if you useScale[First@g2, 2, 0, 0]
(with the third argument specifying the point that is kept fixed) you can use-1,1
instead of-1,1/2
) , that is, you can useShow[g1, Graphics@Translate[Scale[First@g2, 2, 0, 0], -1, 1], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
$endgroup$
– kglr
May 16 at 20:33
1
$begingroup$
... sinceScale[First@g2, 2]
fixes the center (1/2,1/2
) the origin of the rectangle is already shifted by-1/2,1/2
beforeTranslate
is applied. (CompareShow[g1, Graphics@Scale[First@g2, 2], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
andShow[g1, Graphics@Scale[First@g2, 2, 0,0], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
$endgroup$
– kglr
May 16 at 20:37
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
May 16 at 20:44
add a comment |
$begingroup$
Thanks @kglr for the answer. Could you explain how the second argument ofTranslate
is determined? Why it is-1, 1/2
instead of-1, 1
?
$endgroup$
– nanjun
May 16 at 20:07
1
$begingroup$
@nanjun, if you useScale[First@g2, 2, 0, 0]
(with the third argument specifying the point that is kept fixed) you can use-1,1
instead of-1,1/2
) , that is, you can useShow[g1, Graphics@Translate[Scale[First@g2, 2, 0, 0], -1, 1], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
$endgroup$
– kglr
May 16 at 20:33
1
$begingroup$
... sinceScale[First@g2, 2]
fixes the center (1/2,1/2
) the origin of the rectangle is already shifted by-1/2,1/2
beforeTranslate
is applied. (CompareShow[g1, Graphics@Scale[First@g2, 2], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
andShow[g1, Graphics@Scale[First@g2, 2, 0,0], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
$endgroup$
– kglr
May 16 at 20:37
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
May 16 at 20:44
$begingroup$
Thanks @kglr for the answer. Could you explain how the second argument of
Translate
is determined? Why it is -1, 1/2
instead of -1, 1
?$endgroup$
– nanjun
May 16 at 20:07
$begingroup$
Thanks @kglr for the answer. Could you explain how the second argument of
Translate
is determined? Why it is -1, 1/2
instead of -1, 1
?$endgroup$
– nanjun
May 16 at 20:07
1
1
$begingroup$
@nanjun, if you use
Scale[First@g2, 2, 0, 0]
(with the third argument specifying the point that is kept fixed) you can use -1,1
instead of -1,1/2
) , that is, you can use Show[g1, Graphics@Translate[Scale[First@g2, 2, 0, 0], -1, 1], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
$endgroup$
– kglr
May 16 at 20:33
$begingroup$
@nanjun, if you use
Scale[First@g2, 2, 0, 0]
(with the third argument specifying the point that is kept fixed) you can use -1,1
instead of -1,1/2
) , that is, you can use Show[g1, Graphics@Translate[Scale[First@g2, 2, 0, 0], -1, 1], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
$endgroup$
– kglr
May 16 at 20:33
1
1
$begingroup$
... since
Scale[First@g2, 2]
fixes the center (1/2,1/2
) the origin of the rectangle is already shifted by -1/2,1/2
before Translate
is applied. (Compare Show[g1, Graphics@Scale[First@g2, 2], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
and Show[g1, Graphics@Scale[First@g2, 2, 0,0], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
$endgroup$
– kglr
May 16 at 20:37
$begingroup$
... since
Scale[First@g2, 2]
fixes the center (1/2,1/2
) the origin of the rectangle is already shifted by -1/2,1/2
before Translate
is applied. (Compare Show[g1, Graphics@Scale[First@g2, 2], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
and Show[g1, Graphics@Scale[First@g2, 2, 0,0], AspectRatio -> 1, Axes -> True, ImageSize -> 230]
$endgroup$
– kglr
May 16 at 20:37
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
May 16 at 20:44
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
May 16 at 20:44
add a comment |
$begingroup$
I'm not saying that this is what you need for your problem, but sometimes when you want to superimpose graphics like this, you're looking for Inset
:
Show[
g1,
Graphics@Inset[
Show[g2, PlotRangePadding -> 0],
0, 0, Center, Center, 2, 2
],
Axes -> True, ImageSize -> 230
]
$endgroup$
add a comment |
$begingroup$
I'm not saying that this is what you need for your problem, but sometimes when you want to superimpose graphics like this, you're looking for Inset
:
Show[
g1,
Graphics@Inset[
Show[g2, PlotRangePadding -> 0],
0, 0, Center, Center, 2, 2
],
Axes -> True, ImageSize -> 230
]
$endgroup$
add a comment |
$begingroup$
I'm not saying that this is what you need for your problem, but sometimes when you want to superimpose graphics like this, you're looking for Inset
:
Show[
g1,
Graphics@Inset[
Show[g2, PlotRangePadding -> 0],
0, 0, Center, Center, 2, 2
],
Axes -> True, ImageSize -> 230
]
$endgroup$
I'm not saying that this is what you need for your problem, but sometimes when you want to superimpose graphics like this, you're looking for Inset
:
Show[
g1,
Graphics@Inset[
Show[g2, PlotRangePadding -> 0],
0, 0, Center, Center, 2, 2
],
Axes -> True, ImageSize -> 230
]
answered May 16 at 20:02
C. E.C. E.
52.3k3102209
52.3k3102209
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f198521%2fhow-to-scale-and-shift-the-coordinates-of-a-graphics-object%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown