1
$\begingroup$

I have a predefined function that consists of a number plots combined with Show. Is it possible to add another graphics object at a particular position from the function directly? Simplified example:

figure[x0_] := Show[{
Plot[x - x0, {x, -10, 10}],
Plot[x^2, {x, -10, 10}],
Plot[x^3, {x, -10, 10}]
}];
figure[2]

output1

I want to be able to generate something analogous to:

block = Graphics[{LightRed, Rectangle[{-20, -20}, {0, 0}]}];
Show[{
Plot[x - 2, {x, -10, 10}],
Plot[x^2, {x, -10, 10}],
block,
Plot[x^3, {x, -10, 10}]
}]

output2

with figure(2] and block directly, something functionally similar to

Insert[output[2],block,3]

The key point being that the order matters. Is there a convenient way of doing so?

$\endgroup$
  • 2
    $\begingroup$ Insert[figure[2], block[[1]], {1, 3}]? $\endgroup$ – kglr Apr 10 '19 at 1:27
  • $\begingroup$ It seems that the most straightforward thing is to combine them using the Show statement as follows: Show[{ figure[2], block }]. $\endgroup$ – Alexei Boulbitch Apr 10 '19 at 8:07
  • $\begingroup$ @AlexeiBoulbitch The OP wants to insert block between the 2nd part and the 3rd part of figure[2] and precises that the "order matters", hence my answer. $\endgroup$ – andre314 Apr 10 '19 at 8:43
  • $\begingroup$ @ andre314 Exactly that I do not understand, since the result is the same. $\endgroup$ – Alexei Boulbitch Apr 10 '19 at 9:32
  • $\begingroup$ @AlexeiBoulbitch In this case yes. But it is possible that the OP has over-simplified his example. $\endgroup$ – andre314 Apr 10 '19 at 9:47
1
$\begingroup$
Insert[figure[2], block[[1]], {1, 3}]

enter image description here

| improve this answer | |
$\endgroup$
0
$\begingroup$

You can do :

figure[x0_] := 
  Show[{Plot[x - x0, {x, -10, 10}], Plot[x^2, {x, -10, 10}], 
    Plot[x^3, {x, -10, 10}]}];  

block = Graphics[{LightRed, Rectangle[{-20, -20}, {0, 0}]}];  

Show[
   Graphics[figure[2][[1, 1]]]
 , Graphics[figure[2][[1, 2]]]
 , block
 , Graphics[figure[2][[1, 3]]]
 , Options[figure[2]]]

enter image description here

Options[figure[2]] retrieves the original options of figure[2] that are lost when extracting Graphics[figure[2][[1, 1]]].

EDIT

Note that Show[{ figure[2], block }]doesn't give the result expected by the OP :

> Show[{ figure[2], block }]

enter image description here

| improve this answer | |
$\endgroup$

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.