Adding y=x to a matplotlib scatter plot if I haven't kept track of all the data points that went in

后端 未结 3 1204
迷失自我
迷失自我 2020-12-14 08:17

Here\'s some code that does scatter plot of a number of different series using matplotlib and then adds the line y=x:

import numpy as np, matplotlib.pyplot a         


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-14 08:35

    If you set scalex and scaley to False, it saves a bit of bookkeeping. This is what I have been using lately to overlay y=x:

    xpoints = ypoints = plt.xlim()
    plt.plot(xpoints, ypoints, linestyle='--', color='k', lw=3, scalex=False, scaley=False)
    

    or if you've got an axis:

    xpoints = ypoints = ax.get_xlim()
    ax.plot(xpoints, ypoints, linestyle='--', color='k', lw=3, scalex=False, scaley=False)
    

    Of course, this won't give you a square aspect ratio. If you care about that, go with Paul H's solution.

提交回复
热议问题