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?
Bookshelves: the intruder
Gambler's Fallacy Dice
Why does string strummed with finger sound different from the one strummed with pick?
Divisor Rich and Poor Numbers
Why are stats in Angband written as 18/** instead of 19, 20...?
Why use a retrograde orbit?
FIFO data structure in pure C
Does the talk count as invited if my PI invited me?
When did Britain learn about the American Declaration of Independence?
Can ThermodynamicData be used with NSolve?
How to scale and shift the coordinates of a Graphics object?
Why does the setUID bit work inconsistently?
French equivalent of the German expression "flöten gehen"
How can I monitor the bulk API limit?
Former Employer just sent me an IP Agreement
Is it possible to determine from only a photo of a cityscape whether it was taken close with wide angle or from a distance with zoom?
on the truth quest vs in the quest for truth
How does this piece of code determine array size without using sizeof( )?
Why does the U.S military use mercenaries?
Driving a school bus in the USA
Alternative classical explanation of the Stern-Gerlach Experiment?
What technology would Dwarves need to forge titanium?
Failing students when it might cause them economic ruin
How to draw pentagram-like shape in Latex?
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 5 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
4 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
4 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
4 hours ago
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
4 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
4 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
4 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
4 hours ago
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
4 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
4 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
4 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
4 hours ago
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
4 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 3 hours ago
answered 5 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
4 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
4 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
4 hours ago
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
4 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
4 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
4 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
4 hours ago
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
4 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
4 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
4 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
4 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
4 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
4 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
4 hours ago
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
4 hours ago
$begingroup$
Thank you @kglr for the explanation, which was very clear.
$endgroup$
– nanjun
4 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 4 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