Linestyle in matplotlib step function

前端 未结 1 1452
广开言路
广开言路 2021-01-03 22:02

Is it possible to set the linestyle in a matplotlib step function to dashed, dotted, etc.?

I\'ve tried:

step(x, linestyle=\'--\'), 
step(x, \'--\')
         


        
相关标签:
1条回答
  • 2021-01-03 22:31

    As of mpl 1.3.0 this is fixed upstream


    You have to come at it a bit sideways as step seems to ignore linestyle. If you look at what step is doing underneath, it is just a thin wrapper for plot.

    You can do what you want by talking to plot directly:

    import matplotlib.pyplot as plt
    
    plt.plot(range(5), range(5), linestyle='--', drawstyle='steps')
    plt.plot(range(5), range(5)[::-1], linestyle=':', drawstyle='steps')
    plt.xlim([-1, 5])
    plt.ylim([-1, 5])
    

    example

    ['steps', 'steps-pre', 'steps-mid', 'steps-post'] are the valid values for drawstyle and control where the step is drawn.

    Pull request resulting from this question, I personally think this is a bug. [edit: this has been pulled into master and should show up in v1.3.0].

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