pythonpandasmatplotlib

Pandas & MatPlotLib: Plot a Bar Graph on Existing Scatter Plot or Vice Versa


I have a line graph (plotted using plot(x,y) funstion) plotted in a window, then, would it be possible to Plot a bar graph in/on the same window for visual analysis of the data that was plotted?


Solution

  • Yes, you will need to work a little harder and use the axes of the plot:

    import numpy as np
    import matplotlib.pyplot as plt
    
    x= np.arange(5)
    y1=np.arange(5)
    y2 = np.ones(5)
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(x,y1)
    ax.bar(x,y2)
    plt.show()
    

    enter image description here