matplotlib and subplots properties

前端 未结 1 859
鱼传尺愫
鱼传尺愫 2020-12-09 10:00

I\'m adding a matplotlib figure to a canvas so that I may integrate it with pyqt in my application. I were looking around and using plt.add_subplot(111) seem to

相关标签:
1条回答
  • 2020-12-09 10:12

    plt.subplot returns a subplot object which is a type of axes object. It has two methods for adding axis labels: set_xlabel and set_ylabel:

    ax = plt.subplot('111')
    ax.set_xlabel('X Axis')
    ax.set_ylabel('Y Axis')
    

    You could also call plt.xlabel and plt.ylabel (like you did before) and specify the axes to which you want the label applied.

    ax = plt.subplot('111')
    plt.xlabel('X Axis', axes=ax)
    plt.ylabel('Y Axis', axes=ax)
    

    Since you only have one axes, you could also omit the axes kwarg since the label will automatically be applied to the current axes if one isn't specified.

    ax = plt.subplot('111')
    plt.xlabel('X Axis')
    plt.ylabel('Y Axis')
    
    0 讨论(0)
提交回复
热议问题