9

I'm using "ipython jupyter notebook". My question is:

How to add the axis lines to the plot, ie. y=0 and x=0:

%matplotlib inline
from numpy import *
from matplotlib.pyplot import *
nil=seterr(divide='ignore', invalid='ignore')

t = arange(-2, 2, 0.1)
y1 = exp(t)
y2 = exp(-t)

subplot(121)
title('y=exp(t)')
ylabel('y')
xlabel('t')
grid()
plot(t, y1, '-')

subplot(122)
title('y=exp(-t)')
ylabel('y')
xlabel('t')
grid()
plot(t, y2, '-')
show()

enter image description here

1
  • Possibly you are looking for the "zeroed spines" case in this example? Commented Nov 8, 2018 at 2:40

2 Answers 2

9

The easiest way to accomplish this (without the fancy arrowheads, unfortunately) would be to use axvline and axhline to draw lines at x=0 and y=0, respectively:

t = arange(-2, 2, 0.1)
y2 = exp(-t)
axhline(0,color='red') # x = 0
axvline(0,color='red') # y = 0
grid()
plot(t, y2, '-')
show()

Example

Sign up to request clarification or add additional context in comments.

Comments

1

You can use something like this:

import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
x= np.zeros(10)        #range of X values
y= np.arange(-5,5,1)   #range of Y values
plt.plot(x,y, "ro")
plt.show()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.