ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 26 Dec 2020 07:10:19 +0100Combined 2d plot: how to change the size of the object?https://ask.sagemath.org/question/54899/combined-2d-plot-how-to-change-the-size-of-the-object/I have created a matrix plot and a line and combined them as follows:
m = matrix_plot([[1,0,1,0,1,0,1,0],
[0,1,0,1,0,1,0,1],
[1,0,1,0,1,0,1,0],
[0,1,0,1,0,1,0,1],
[1,0,1,0,1,0,1,0],
[0,1,0,1,0,1,0,1],
[1,0,1,0,1,0,1,0],
[0,1,0,1,0,1,0,1],
[1,0,1,0,1,0,1,0]],
aspect_ratio=1,
frame=False)
Q = line([(-0.5, 0), (1, 1)], thickness=3)
Combined graphics is `(m+Q)`.
I would like to change the size of `(m+Q)`, but `(m+Q).set_axes_range()` does not affect the values.
Here is an example showing no change when using `set_axes_range()`:
- https://sagecell.sagemath.org/?q=wnkqye
What method should I use?Fri, 25 Dec 2020 21:31:32 +0100https://ask.sagemath.org/question/54899/combined-2d-plot-how-to-change-the-size-of-the-object/Answer by slelievre for <p>I have created a matrix plot and a line and combined them as follows:</p>
<pre><code>m = matrix_plot([[1,0,1,0,1,0,1,0],
[0,1,0,1,0,1,0,1],
[1,0,1,0,1,0,1,0],
[0,1,0,1,0,1,0,1],
[1,0,1,0,1,0,1,0],
[0,1,0,1,0,1,0,1],
[1,0,1,0,1,0,1,0],
[0,1,0,1,0,1,0,1],
[1,0,1,0,1,0,1,0]],
aspect_ratio=1,
frame=False)
Q = line([(-0.5, 0), (1, 1)], thickness=3)
</code></pre>
<p>Combined graphics is <code>(m+Q)</code>.</p>
<p>I would like to change the size of <code>(m+Q)</code>, but <code>(m+Q).set_axes_range()</code> does not affect the values.</p>
<p>Here is an example showing no change when using <code>set_axes_range()</code>:</p>
<ul>
<li><a href="https://sagecell.sagemath.org/?q=wnkqye">https://sagecell.sagemath.org/?q=wnkqye</a></li>
</ul>
<p>What method should I use?</p>
https://ask.sagemath.org/question/54899/combined-2d-plot-how-to-change-the-size-of-the-object/?answer=54913#post-id-54913You need to give `m + Q` a new name.
Otherwise when you do `(m + Q).set_axes_range(...)` that gets applied to an object which you can no longer recover.
And when you later do `(m + Q).get_axes_range(...)` you are computing `m + Q` again and that cannot know about the operation you did on the lost object.
Try this:
sage: mQ = m + Q
sage: mQ.set_axes_range(xmin=-0.2, xmax=5.5, ymin=-0.5, ymax=1)
sage: print(mQ.get_axes_range())
sage: mQ.show()Sat, 26 Dec 2020 02:07:49 +0100https://ask.sagemath.org/question/54899/combined-2d-plot-how-to-change-the-size-of-the-object/?answer=54913#post-id-54913Comment by PatB for <p>You need to give <code>m + Q</code> a new name.</p>
<p>Otherwise when you do <code>(m + Q).set_axes_range(...)</code> that gets applied to an object which you can no longer recover.</p>
<p>And when you later do <code>(m + Q).get_axes_range(...)</code> you are computing <code>m + Q</code> again and that cannot know about the operation you did on the lost object.</p>
<p>Try this:</p>
<pre><code>sage: mQ = m + Q
sage: mQ.set_axes_range(xmin=-0.2, xmax=5.5, ymin=-0.5, ymax=1)
sage: print(mQ.get_axes_range())
sage: mQ.show()
</code></pre>
https://ask.sagemath.org/question/54899/combined-2d-plot-how-to-change-the-size-of-the-object/?comment=54917#post-id-54917Yes, that makes perfect sense!
I need to create a reference to this combined object - as you suggested mQ = m+Q allows me to do mQ.set_axes_range(...)
Merci Beaucoup! Une réponse le jour même de Noël!Sat, 26 Dec 2020 05:24:45 +0100https://ask.sagemath.org/question/54899/combined-2d-plot-how-to-change-the-size-of-the-object/?comment=54917#post-id-54917Comment by slelievre for <p>You need to give <code>m + Q</code> a new name.</p>
<p>Otherwise when you do <code>(m + Q).set_axes_range(...)</code> that gets applied to an object which you can no longer recover.</p>
<p>And when you later do <code>(m + Q).get_axes_range(...)</code> you are computing <code>m + Q</code> again and that cannot know about the operation you did on the lost object.</p>
<p>Try this:</p>
<pre><code>sage: mQ = m + Q
sage: mQ.set_axes_range(xmin=-0.2, xmax=5.5, ymin=-0.5, ymax=1)
sage: print(mQ.get_axes_range())
sage: mQ.show()
</code></pre>
https://ask.sagemath.org/question/54899/combined-2d-plot-how-to-change-the-size-of-the-object/?comment=54918#post-id-54918If that answers your question, you can mark the answer as accepted, which will also marked your question as solved.Sat, 26 Dec 2020 07:07:04 +0100https://ask.sagemath.org/question/54899/combined-2d-plot-how-to-change-the-size-of-the-object/?comment=54918#post-id-54918Comment by slelievre for <p>You need to give <code>m + Q</code> a new name.</p>
<p>Otherwise when you do <code>(m + Q).set_axes_range(...)</code> that gets applied to an object which you can no longer recover.</p>
<p>And when you later do <code>(m + Q).get_axes_range(...)</code> you are computing <code>m + Q</code> again and that cannot know about the operation you did on the lost object.</p>
<p>Try this:</p>
<pre><code>sage: mQ = m + Q
sage: mQ.set_axes_range(xmin=-0.2, xmax=5.5, ymin=-0.5, ymax=1)
sage: print(mQ.get_axes_range())
sage: mQ.show()
</code></pre>
https://ask.sagemath.org/question/54899/combined-2d-plot-how-to-change-the-size-of-the-object/?comment=54919#post-id-54919From your profile page you can visit all your past questions and accept the answers that solve these questions to mark the questions as solved. This is done by clicking the "✓" below the "upvote" and "downvote" buttons and the answer's score.Sat, 26 Dec 2020 07:10:19 +0100https://ask.sagemath.org/question/54899/combined-2d-plot-how-to-change-the-size-of-the-object/?comment=54919#post-id-54919