Ask Your Question

How can matplotlib graph axis be moved?

asked 2012-07-07 06:50:21 -0600

AndreWin gravatar image

updated 2012-07-07 21:50:34 -0600

Hello! I created test simple plot with matplotlib on using the following sintax:

import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])

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.


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 I typed the following code:

import matplotlib.pyplot as plt
plt.plot([0, 5, 10, 15,20,25], [0, 5, 0, -5, 0, 5], linewidth=2, color='blue')'off')
plt.axhline(y=0, color='black')
plt.axvline(x=0, color='black')

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.

edit retag flag offensive close merge delete


I'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!

kcrisman gravatar imagekcrisman ( 2012-07-07 16:12:15 -0600 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2012-07-08 00:17:54 -0600

AndreWin gravatar image

updated 2012-07-08 00:38:06 -0600

I founded answer for my question! It can be founded at . More results can be founded at . The code is below:

import matplotlib.pyplot as plt
ax = fig.add_subplot(111)
for direction in ["left","bottom"]:
for direction in ["right","top"]:
plt.plot([0, 5, 10, 15,20,25], [0, 5, 0, -5, 0, 5], linewidth=2, color='blue')

Thanks to anyone!

edit flag offensive delete link more

answered 2012-07-07 09:47:07 -0600

fidbc gravatar image

updated 2012-07-07 12:15:52 -0600

Hi! You can find more details about pyplot here:

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])

This produces: image description

The original plot was:

image description

Maybe creating the plots using functions from sage might be easier than using matplotlib.

Edit: Added images to illustrate difference and updated link.

edit flag offensive delete link more


Sorry, but your code don't solve this ploblem. I tried it and didn't see any difference from my graph.

AndreWin gravatar imageAndreWin ( 2012-07-07 09:55:58 -0600 )edit

Besides I don't know how to use your link (

AndreWin gravatar imageAndreWin ( 2012-07-07 09:59:05 -0600 )edit

Sorry, I might've missunderstood your question. I've added some images to contrast the differences. Is this what you wanted to produce?

fidbc gravatar imagefidbc ( 2012-07-07 12:18:42 -0600 )edit

Fidelbc, thank you for your help! Your link helped me at some extent. I realized my question wasn't detailed and I updated my question.

AndreWin gravatar imageAndreWin ( 2012-07-07 21:52:50 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2012-07-07 06:50:21 -0600

Seen: 4,345 times

Last updated: Jul 08 '12