Reduce x-axis entries in an area plot in Matplotlib

后端 未结 1 1226
予麋鹿
予麋鹿 2021-01-28 07:25

I want to have not-stacked area plot with overalapping curves that are transparent in a sense that you can see both curves (similar to Custom legend for overlapping transparent

相关标签:
1条回答
  • 2021-01-28 08:01

    To set custom labels, you can take the following approach shown on a toy example:

    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.ticker as ticker
    
    x = [0,5,9,10,15,22,55,88,122]
    y = x
    fig, ax = plt.subplots()
    ax.plot(x,y)
    xticks = ['00:00', '01:00', '02:00' , '24:00']
    xvals = [0,22,88,122] 
    ax.set(xticks=xvals, xticklabels=xticks)
    plt.show()
    

    In your particular case, you've values every 5 minutes. You want to have ticks every 60 minutes.

    xticks=['00:00','01:00','02:00','03:00','04:00','05:00',
          '06:00','07:00','08:00','09:00','10:00','11:00',
          '12:00','13:00','14:00','15:00','16:00','17:00',
          '18:00','19:00','20:00','21:00','22:00','23:00']
    
    xvals=power_values[::12] # every 12th element corresponds to 1hr.
    
    0 讨论(0)
提交回复
热议问题