Cliff
Cliff

Reputation: 63

python plot using pylab

I'm very new to python just started using it from a day or two.. I'm using Anaconda python notebook. so I'm trying to plot, but in the output there is only grid and nothing no lines or anything, my program is as follows

from __future__ import print_function
from decimal import *
import numpy as np
from sympy import *
import pylab

k = Symbol('k')
A = Symbol('A')
E = Symbol('E')
d = Symbol('d')
C = Symbol('C')
Y = Symbol('Y')

Y = []

for A in np.arange(-1.11, 1.11, 0.002):        
    s = sin(A)
    c = cos(A)
    C = (s/A) + c
    Y.append(C)      

pylab.plot(C, A)   
grid()

xlabel('$x$')
ylabel('$y$')

title('graph')

The code doesn't show any errors, but will you please help me as to what am I doing wrong here ...

Upvotes: 1

Views: 821

Answers (3)

Joël
Joël

Reputation: 2822

If I do this, I have a figure with both grid and graph:

import pylab
pylab.plot([1, 3, 4], [1, 2, 3])
pylab.grid()
pylab.show()

But if I do this, I have first a figure with only the graph, and then with only the grid:

import pylab
pylab.plot([1, 3, 4], [1, 2, 3])
pylab.show()  # here I get only the graph
pylab.grid()
pylab.show()  # here I get only the grid

Note: calling grid(), title(), xlabel and ylabel as you do shall not work; each time it shall be prepended by pylab.. Is that really your code?

Upvotes: 0

Steve Barnes
Steve Barnes

Reputation: 28370

You are mixing different plotting functions from pylab, sympy and you are not giving an X axis:

import numpy as np
from matplotlib import pyplot
Y=[]
X = np.arange(-1.11, 1.11, 0.002)
for A in X:
     s = np.sin(A)
     c = np.cos(A)
     C = (s/A)+c
     Y.append(C)
line, = pyplot.plot(X,Y, "-b")
pyplot.grid(True)
pyplot.show()

Gives me: enter image description here

Upvotes: 2

oz123
oz123

Reputation: 28858

What about showing the graph with

 pylab.show()

Upvotes: 1

Related Questions