Matplotlib - Move X-Axis label downwards, but not X-Axis Ticks

后端 未结 2 1620
无人共我
无人共我 2020-11-28 04:10

I\'m using Matplotlib to plot a histogram. Using tips from my previous question: Matplotlib - label each bin, I\'ve more or less go the kinks worked out.

There\'s on

相关标签:
2条回答
  • 2020-11-28 04:50

    If the variable ax.xaxis._autolabelpos = True, matplotlib sets the label position in function _update_label_position in axis.py according to (some excerpts):

        bboxes, bboxes2 = self._get_tick_bboxes(ticks_to_draw, renderer)
        bbox = mtransforms.Bbox.union(bboxes)
        bottom = bbox.y0
        x, y = self.label.get_position()
        self.label.set_position((x, bottom - self.labelpad * self.figure.dpi / 72.0))
    

    You can set the label position independently of the ticks by using:

        ax.xaxis.set_label_coords(x0, y0)
    

    that sets _autolabelpos to False or as mentioned above by changing the labelpad parameter.

    0 讨论(0)
  • 2020-11-28 05:07

    use labelpad parameter:

    pl.xlabel("...", labelpad=20)
    

    or set it after:

    ax.xaxis.labelpad = 20
    
    0 讨论(0)
提交回复
热议问题