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.Sun, 08 Jul 2012 07:17:54 +0200How can matplotlib graph axis be moved?https://ask.sagemath.org/question/9142/how-can-matplotlib-graph-axis-be-moved/Hello! I created test simple plot with matplotlib on www.sagenb.com using the following sintax:
import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.savefig('1.png')
By default the axes are around the graph. But I want axes to be intersected at (0,0) point. I tried to find answer at matplotlib online documentation but not found.
**Upd_1:**
I would like to explain my problem more detail.
Original graph has frame around it. Axes of this graph are located on the graph bordes. I want frame to be switched off and axis lines to be intersected at (0,0) point. Such graphs are drawn with Sage by default (I'm glad to upload some pictures, but my karma isn't enough to do it). Thanks to the help of [fidelbc](http://ask.sagemath.org/users/382/fidelbc/) I typed the following code:
import matplotlib.pyplot as plt
plt.clf()
plt.plot([0, 5, 10, 15,20,25], [0, 5, 0, -5, 0, 5], linewidth=2, color='blue')
plt.box('off')
plt.grid(True)
plt.axhline(y=0, color='black')
plt.axvline(x=0, color='black')
plt.savefig('1.png')
New graph responds my idea at more extent and I want to draw arrows on axes and ticks with its label to be located near new horisontal axes. Please help me to set these parameters or just move graph axis. Thanks.Sat, 07 Jul 2012 13:50:21 +0200https://ask.sagemath.org/question/9142/how-can-matplotlib-graph-axis-be-moved/Comment by kcrisman for <p>Hello! I created test simple plot with matplotlib on <a href="http://www.sagenb.com">www.sagenb.com</a> using the following sintax:</p>
<pre><code>import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.savefig('1.png')
</code></pre>
<p>By default the axes are around the graph. But I want axes to be intersected at (0,0) point. I tried to find answer at matplotlib online documentation but not found.</p>
<p><strong>Upd_1:</strong></p>
<p>I would like to explain my problem more detail.
Original graph has frame around it. Axes of this graph are located on the graph bordes. I want frame to be switched off and axis lines to be intersected at (0,0) point. Such graphs are drawn with Sage by default (I'm glad to upload some pictures, but my karma isn't enough to do it). Thanks to the help of <a href="http://ask.sagemath.org/users/382/fidelbc/">fidelbc</a> I typed the following code:</p>
<pre><code>import matplotlib.pyplot as plt
plt.clf()
plt.plot([0, 5, 10, 15,20,25], [0, 5, 0, -5, 0, 5], linewidth=2, color='blue')
plt.box('off')
plt.grid(True)
plt.axhline(y=0, color='black')
plt.axvline(x=0, color='black')
plt.savefig('1.png')
</code></pre>
<p>New graph responds my idea at more extent and I want to draw arrows on axes and ticks with its label to be located near new horisontal axes. Please help me to set these parameters or just move graph axis. Thanks.</p>
https://ask.sagemath.org/question/9142/how-can-matplotlib-graph-axis-be-moved/?comment=19431#post-id-19431I'll just point out that this really isn't a Sage question at all... though we're happy to be a place to share info!Sat, 07 Jul 2012 23:12:15 +0200https://ask.sagemath.org/question/9142/how-can-matplotlib-graph-axis-be-moved/?comment=19431#post-id-19431Answer by fidbc for <p>Hello! I created test simple plot with matplotlib on <a href="http://www.sagenb.com">www.sagenb.com</a> using the following sintax:</p>
<pre><code>import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.savefig('1.png')
</code></pre>
<p>By default the axes are around the graph. But I want axes to be intersected at (0,0) point. I tried to find answer at matplotlib online documentation but not found.</p>
<p><strong>Upd_1:</strong></p>
<p>I would like to explain my problem more detail.
Original graph has frame around it. Axes of this graph are located on the graph bordes. I want frame to be switched off and axis lines to be intersected at (0,0) point. Such graphs are drawn with Sage by default (I'm glad to upload some pictures, but my karma isn't enough to do it). Thanks to the help of <a href="http://ask.sagemath.org/users/382/fidelbc/">fidelbc</a> I typed the following code:</p>
<pre><code>import matplotlib.pyplot as plt
plt.clf()
plt.plot([0, 5, 10, 15,20,25], [0, 5, 0, -5, 0, 5], linewidth=2, color='blue')
plt.box('off')
plt.grid(True)
plt.axhline(y=0, color='black')
plt.axvline(x=0, color='black')
plt.savefig('1.png')
</code></pre>
<p>New graph responds my idea at more extent and I want to draw arrows on axes and ticks with its label to be located near new horisontal axes. Please help me to set these parameters or just move graph axis. Thanks.</p>
https://ask.sagemath.org/question/9142/how-can-matplotlib-graph-axis-be-moved/?answer=13807#post-id-13807Hi!
You can find more details about pyplot here: [x0.no/5yi3](http://x0.no/5yi3)
You can try adding two lines to your code to get the axis intersected at (0,0), like this.
import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.axhline(y=0)
plt.axvline(x=0)
plt.savefig('1.png')
This produces:
![image description](/upfiles/13416992836877859.png)
The original plot was:
![image description](/upfiles/13416992504639967.png)
Maybe creating the plots using functions from sage might be easier than using matplotlib.
**Edit**: Added images to illustrate difference and updated link.Sat, 07 Jul 2012 16:47:07 +0200https://ask.sagemath.org/question/9142/how-can-matplotlib-graph-axis-be-moved/?answer=13807#post-id-13807Comment by AndreWin for <p>Hi!
You can find more details about pyplot here: <a href="http://x0.no/5yi3">x0.no/5yi3</a></p>
<p>You can try adding two lines to your code to get the axis intersected at (0,0), like this.</p>
<pre><code>import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.axhline(y=0)
plt.axvline(x=0)
plt.savefig('1.png')
</code></pre>
<p>This produces:
<img alt="image description" src="/upfiles/13416992836877859.png"/></p>
<p>The original plot was:</p>
<p><img alt="image description" src="/upfiles/13416992504639967.png"/></p>
<p>Maybe creating the plots using functions from sage might be easier than using matplotlib.</p>
<p><strong>Edit</strong>: Added images to illustrate difference and updated link.</p>
https://ask.sagemath.org/question/9142/how-can-matplotlib-graph-axis-be-moved/?comment=19435#post-id-19435Sorry, but your code don't solve this ploblem. I tried it and didn't see any difference from my graph.Sat, 07 Jul 2012 16:55:58 +0200https://ask.sagemath.org/question/9142/how-can-matplotlib-graph-axis-be-moved/?comment=19435#post-id-19435Comment by AndreWin for <p>Hi!
You can find more details about pyplot here: <a href="http://x0.no/5yi3">x0.no/5yi3</a></p>
<p>You can try adding two lines to your code to get the axis intersected at (0,0), like this.</p>
<pre><code>import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.axhline(y=0)
plt.axvline(x=0)
plt.savefig('1.png')
</code></pre>
<p>This produces:
<img alt="image description" src="/upfiles/13416992836877859.png"/></p>
<p>The original plot was:</p>
<p><img alt="image description" src="/upfiles/13416992504639967.png"/></p>
<p>Maybe creating the plots using functions from sage might be easier than using matplotlib.</p>
<p><strong>Edit</strong>: Added images to illustrate difference and updated link.</p>
https://ask.sagemath.org/question/9142/how-can-matplotlib-graph-axis-be-moved/?comment=19428#post-id-19428Fidelbc, thank you for your help! Your link helped me at some extent. I realized my question wasn't detailed and I updated my question.Sun, 08 Jul 2012 04:52:50 +0200https://ask.sagemath.org/question/9142/how-can-matplotlib-graph-axis-be-moved/?comment=19428#post-id-19428Comment by fidbc for <p>Hi!
You can find more details about pyplot here: <a href="http://x0.no/5yi3">x0.no/5yi3</a></p>
<p>You can try adding two lines to your code to get the axis intersected at (0,0), like this.</p>
<pre><code>import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.axhline(y=0)
plt.axvline(x=0)
plt.savefig('1.png')
</code></pre>
<p>This produces:
<img alt="image description" src="/upfiles/13416992836877859.png"/></p>
<p>The original plot was:</p>
<p><img alt="image description" src="/upfiles/13416992504639967.png"/></p>
<p>Maybe creating the plots using functions from sage might be easier than using matplotlib.</p>
<p><strong>Edit</strong>: Added images to illustrate difference and updated link.</p>
https://ask.sagemath.org/question/9142/how-can-matplotlib-graph-axis-be-moved/?comment=19432#post-id-19432Sorry, I might've missunderstood your question. I've added some images to contrast the differences. Is this what you wanted to produce?Sat, 07 Jul 2012 19:18:42 +0200https://ask.sagemath.org/question/9142/how-can-matplotlib-graph-axis-be-moved/?comment=19432#post-id-19432Comment by AndreWin for <p>Hi!
You can find more details about pyplot here: <a href="http://x0.no/5yi3">x0.no/5yi3</a></p>
<p>You can try adding two lines to your code to get the axis intersected at (0,0), like this.</p>
<pre><code>import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.axhline(y=0)
plt.axvline(x=0)
plt.savefig('1.png')
</code></pre>
<p>This produces:
<img alt="image description" src="/upfiles/13416992836877859.png"/></p>
<p>The original plot was:</p>
<p><img alt="image description" src="/upfiles/13416992504639967.png"/></p>
<p>Maybe creating the plots using functions from sage might be easier than using matplotlib.</p>
<p><strong>Edit</strong>: Added images to illustrate difference and updated link.</p>
https://ask.sagemath.org/question/9142/how-can-matplotlib-graph-axis-be-moved/?comment=19434#post-id-19434Besides I don't know how to use your link (x0.no/5yi3).Sat, 07 Jul 2012 16:59:05 +0200https://ask.sagemath.org/question/9142/how-can-matplotlib-graph-axis-be-moved/?comment=19434#post-id-19434Answer by AndreWin for <p>Hello! I created test simple plot with matplotlib on <a href="http://www.sagenb.com">www.sagenb.com</a> using the following sintax:</p>
<pre><code>import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.savefig('1.png')
</code></pre>
<p>By default the axes are around the graph. But I want axes to be intersected at (0,0) point. I tried to find answer at matplotlib online documentation but not found.</p>
<p><strong>Upd_1:</strong></p>
<p>I would like to explain my problem more detail.
Original graph has frame around it. Axes of this graph are located on the graph bordes. I want frame to be switched off and axis lines to be intersected at (0,0) point. Such graphs are drawn with Sage by default (I'm glad to upload some pictures, but my karma isn't enough to do it). Thanks to the help of <a href="http://ask.sagemath.org/users/382/fidelbc/">fidelbc</a> I typed the following code:</p>
<pre><code>import matplotlib.pyplot as plt
plt.clf()
plt.plot([0, 5, 10, 15,20,25], [0, 5, 0, -5, 0, 5], linewidth=2, color='blue')
plt.box('off')
plt.grid(True)
plt.axhline(y=0, color='black')
plt.axvline(x=0, color='black')
plt.savefig('1.png')
</code></pre>
<p>New graph responds my idea at more extent and I want to draw arrows on axes and ticks with its label to be located near new horisontal axes. Please help me to set these parameters or just move graph axis. Thanks.</p>
https://ask.sagemath.org/question/9142/how-can-matplotlib-graph-axis-be-moved/?answer=13809#post-id-13809I founded answer for my question! It can be founded at http://commons.wikimedia.org/wiki/File:Conic_x%5E2%2B2xy%2By%5E2?8x%3D0.svg . More results can be founded at http://commons.wikimedia.org/wiki/Category:Made_with_Matplotlib . The code is below:
import matplotlib.pyplot as plt
plt.clf()
fig=figure(figsize=(5,3))
ax = fig.add_subplot(111)
for direction in ["left","bottom"]:
ax.spines[direction].set_position('zero')
ax.spines[direction].set_smart_bounds(True)
for direction in ["right","top"]:
ax.spines[direction].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.grid(True)
plt.plot([0, 5, 10, 15,20,25], [0, 5, 0, -5, 0, 5], linewidth=2, color='blue')
plt.savefig('1.png')
Thanks to anyone!Sun, 08 Jul 2012 07:17:54 +0200https://ask.sagemath.org/question/9142/how-can-matplotlib-graph-axis-be-moved/?answer=13809#post-id-13809