Suggestions to plot overlapping lines in matplotlib?

后端 未结 3 979
清歌不尽
清歌不尽 2020-12-09 17:46

Does anybody have a suggestion on what\'s the best way to present overlapping lines on a plot? I have a lot of them, and I had the idea of having full lines of different col

相关标签:
3条回答
  • 2020-12-09 18:11

    I have the same issue on a plot with a high degree of discretization.

    Here the starting situation:

    import matplotlib.pyplot as plt
    grid=[x for x in range(10)]
    graphs=[
            [1,1,1,4,4,4,3,5,6,0],
            [1,1,1,5,5,5,3,5,6,0],
            [1,1,1,0,0,3,3,2,4,0],
            [1,2,4,4,3,2,3,2,4,0],
            [1,2,3,3,4,4,3,2,6,0],
            [1,1,3,3,0,3,3,5,4,3],
            ]
    
    for gg,graph in enumerate(graphs):
        plt.plot(grid,graph,label='g'+str(gg))
    
    plt.legend(loc=3,bbox_to_anchor=(1,0))
    plt.show()
    

    No one can say where the green and blue lines run exactly

    and my "solution"

    import matplotlib.pyplot as plt
    grid=[x for x in range(10)]
    graphs=[
            [1,1,1,4,4,4,3,5,6,0],
            [1,1,1,5,5,5,3,5,6,0],
            [1,1,1,0,0,3,3,2,4,0],
            [1,2,4,4,3,2,3,2,4,0],
            [1,2,3,3,4,4,3,2,6,0],
            [1,1,3,3,0,3,3,5,4,3],
            ]
    
    for gg,graph in enumerate(graphs):
        lw=10-8*gg/len(graphs)
        ls=['-','--','-.',':'][gg%4]
        plt.plot(grid,graph,label='g'+str(gg), linestyle=ls, linewidth=lw)
    
    plt.legend(loc=3,bbox_to_anchor=(1,0))
    plt.show()
    

    I am grateful for suggestions on improvement!

    0 讨论(0)
  • 2020-12-09 18:11

    imagine your panda data frame is called respone_times, then you can use alpha to set different opacity for your graphs. Check the picture before and after using alpha.

    plt.figure(figsize=(15, 7))
    plt.plot(respone_times,alpha=0.5)
    plt.title('a sample title')
    plt.grid(True)
    plt.show()
    
    0 讨论(0)
  • 2020-12-09 18:14

    Just decrease the opacity of the lines so that they are see-through. You can achieve that using the alpha variable. Example:

    plt.plot(x, y, alpha=0.7)

    Where alpha ranging from 0-1, with 0 being invisible.

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