trouble plotting function
Question: Im trying to write a function, and then plot it. I am new to python and am
having some trouble. I have to be missing information, just not sure where.
Can anyone help?

    
    
    xv= arange(-4,5,1)  
    def f(x):
        if (x<0):
            return log(x)
        elif (0<=x<2):
            return (-x)
        elif (2<x):
            return x**2/(3-x)
    
    xv= arange(-4,5,1)
    y1= log(x)
    y2= (-x)
    y3= x**2/3-x
    
    fig1=figure()
    plot(xv,y1,y2,y3)
    show()
    


Answer: Maybe you are trying to do the following:

    
    
    import numpy as np
    import matplotlib.pyplot as plt
    
    x = np.arange(-4, 5, 1)
    y = np.sin(x)
    
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    ax.plot(x, y)
    plt.show()
    

In your example, it looks like you are also attempting to take `log(x)`? If
this is the case, remember that, mathematically, `log(x)` is complex if `x <
0`.

Hope this helps.

