tick label positions for matplotlib 3D plot

前端 未结 3 2062
说谎
说谎 2021-01-02 10:04

I am trying to work out how to set/correct the position of tick labels for a 3D matplotlib plot. Tick labels do not align with the ticks. The issue seems to be especially pr

相关标签:
3条回答
  • 2021-01-02 10:18

    You can also set the pad argument as negative in the tick_params options for each axis. Like this:

        ax.tick_params(axis='x', which='major', pad=-3)
    

    This might help to adjust the distance between tick labels and axis.

    0 讨论(0)
  • 2021-01-02 10:20

    By using these alignments, I get much better placements:

    ax.set_yticklabels(labels,rotation=-15,
                       verticalalignment='baseline',
                       horizontalalignment='left')
    

    I've modified the example with less tick markers so you can see the placement:

    enter image description here

    0 讨论(0)
  • 2021-01-02 10:23

    They do align, but with the horizontal position centered at the tick. Because of the 3D view this makes them appear a bit below where you would expect them to be. The effect is not related to the amount of ticks but to the width.

    Specifically setting the alignment will help. Try adding:

    ax.set_yticklabels(labels,rotation=-15, va='center', ha='left')
    

    Play around a bit with the different alignments to see which you prefer, i think you're after ha='left'.

    Reducing the padding, distance from the tick, might also help.

    enter image description here

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