matplotlib how to start ticks leaving space from the axis origin

前端 未结 1 1779
失恋的感觉
失恋的感觉 2021-01-12 19:32

I need to plot non-numeric data against dates as a simple line graph. I am using matplotlib.

Here\'s some sample code.

import matplotlib.pyplot as p         


        
相关标签:
1条回答
    • You can "lift" the graph by setting a lower ylim with ax.set_ylim.
    • Marker dots can be added to the plot using the marker = 'o' parameter setting in the call to plt.plot:

    import matplotlib.pyplot as plt
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    
    xticks=['Jan','Feb','Mar','April','May']
    x=[1,2,3,4,5]
    yticks = ['Windy', 'Sunny', 'Rainy', 'Cloudy', 'Snowy']
    y=[2,1,3,5,4]
    
    plt.plot(x,y,'b-', marker = 'o') #.2,.1,.7,.8
    plt.subplots_adjust(left =0.2)
    
    plt.xticks(x,xticks)
    plt.yticks(y,yticks)
    ax.set_ylim(0.5,max(y))
    plt.show()
    

    enter image description here

    0 讨论(0)
提交回复
热议问题