Python axhline, title and axis labels
Question: I am trying to plot a horizontal line over another plot using matplotlib.
Everything works except the title and axis labels never show up. How does this
work?

*Edit-sorry, code looks sort of like this: from matplotlib import pyplot as plt n=100
    
    
    plt.axhline(y=n, label='Old')
    plt.plot([5, 6, 7, 8], [100, 110, 115, 150], 'ro', label='New')
    plt.xlabel=('Example x')
    plt.ylabel=('Example y')
    plt.title=('Example Title')
    plt.legend()
    plt.axis([0,10,50,150])
    plt.show()
    

Everything shows up normally just no title and no axis labels. The legend is
there.


Answer: Try this:

    
    
    fig = plt.figure()
    
    ax = fig.add_subplot(111)
    ax.axhline(y=n, label='Old')
    ax.plot([5, 6, 7, 8], [100, 110, 115, 150], 'ro', label='New')
    
    ax.set_xlabel('Example x')
    ax.set_ylabel('Example y')
    ax.set_title('Example Title')
    
    ax.legend()
    ax.set_xticks([0,10,50,150])
    ax.set_yticks([0,10,50,150])
    
    plt.show()
    

