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?
Pedaling at different gear ratios on flat terrain: what's the point?
Failing students when it might cause them economic ruin
Should I twist DC power and ground wires from a power supply?
How can I monitor the bulk API limit?
How does this piece of code determine array size without using sizeof( )?
Have GoT's showrunners reacted to the poor reception of the final season?
Would a "ring language" be possible?
Will this series of events work to drown the Tarrasque?
How do you cope with rejection?
Can more than one instance of Bend Luck be applied to the same roll by multiple Wild Magic sorcerers?
Quotient of Three Dimensional Torus by Permutation on Coordinates
Can the word crowd refer to just 10 people?
Why is Drogon so much better in battle than Rhaegal and Viserion?
Does a windmilling propeller create more drag than a stopped propeller in an engine out scenario
Good examples of "two is easy, three is hard" in computational sciences
What color to choose as "danger" if the main color of my app is red
Why does Taylor’s series “work”?
Cycling to work - 30mile return
Save my secrets!
French equivalent of the German expression "flöten gehen"
How come Arya Stark wasn't hurt by this in Game of Thrones Season 8 Episode 5?
Are there any symmetric cryptosystems based on computational complexity assumptions?
Why use a retrograde orbit?
Why is the S-duct intake on the Tu-154 uniquely oblong?
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 6 hours ago
nanjunnanjun
46829
46829
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
You can use Scale
and Translate
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
5 hours ago
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
5 hours ago
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
5 hours ago
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
5 hours ago
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
and Translate
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
5 hours ago
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
5 hours ago
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
5 hours ago
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
5 hours ago
add a comment |
$begingroup$
You can use Scale
and Translate
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
5 hours ago
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
5 hours ago
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
5 hours ago
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
5 hours ago
add a comment |
$begingroup$
You can use Scale
and Translate
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
and Translate
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 4 hours ago
answered 6 hours ago
kglrkglr
192k10214434
192k10214434
$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
5 hours ago
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
5 hours ago
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
5 hours ago
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
5 hours ago
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
5 hours ago
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
5 hours ago
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
5 hours ago
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
5 hours ago
$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
5 hours ago
$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
5 hours ago
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
5 hours ago
$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
5 hours ago
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
5 hours ago
$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
5 hours ago
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
5 hours ago
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
5 hours ago
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 6 hours ago
C. E.C. E.
52k3101209
52k3101209
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