简体   繁体   English

Matplotlib:如何在x轴的另一侧出现xtick标签?

[英]Matplotlib: How do I have the xtick labels apear on the other side of the x-axis?

In this bar chart: 在此条形图中:

在此处输入图片说明

How do I make the x-axis labels appear in the bars of the bar-chart and left-aligned with the x-axis? 如何使x轴标签出现在条形图中,并与x轴左对齐?

I tried the ax.xaxis.labelpad() method but it does not seem to do anything. 我尝试了ax.xaxis.labelpad()方法,但它似乎没有任何作用。

you can set the y location of the ticks when you call set_xticklabels . 您可以在调用set_xticklabels时设置刻度线的y位置。 So, if you set y to something small but positive, it should be placed inside the bars. 因此,如果将y设置为小而正的值,则应将其放置在小节内。

For example: 例如:

import matplotlib.pyplot as plt
fig,ax = plt.subplots(1)

ax.bar([0,1,2,3],[7900,9400,8700,9990],facecolor='#5080B0',edgecolor='k',width=0.3)

ax.set_xticks([0.15,1.15,2.15,3.15])

ax.set_xticklabels(['beek1','beek2','orbath','Kroo'],
                   rotation='vertical',y=0.05,va='bottom')

Produces the following plot: 产生以下图:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM