Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 增加y轴和x轴标签的字体(不是y轴和x轴标题)_Python_Matplotlib - Fatal编程技术网

Python 增加y轴和x轴标签的字体(不是y轴和x轴标题)

Python 增加y轴和x轴标签的字体(不是y轴和x轴标题),python,matplotlib,Python,Matplotlib,我有一个要绘制的数据框,数据框(下面代码中的x变量)如下所示: Name1 4 Name2 4 Name3 4 Name4 4 Name5 4 Name6 4 Name7 4 Name8 5 Name9 5 Name10 6 Name11 6 Name12 7 Name13 9 Name14 9 Name15 10 Name16 10 Name17 27 我想在条形图上绘制数据,代码为: import sys import pandas as pd import matplotlib.pypl

我有一个要绘制的数据框,数据框(下面代码中的x变量)如下所示:

Name1 4
Name2 4
Name3 4
Name4 4
Name5 4
Name6 4
Name7 4
Name8 5
Name9 5
Name10 6
Name11 6
Name12 7
Name13 9
Name14 9
Name15 10
Name16 10
Name17 27
我想在条形图上绘制数据,代码为:

import sys
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.ticker import StrMethodFormatter

fam_dict = {}
df = pd.read_csv(open(sys.argv[1]),header=0,sep='\t')
x = df['family_name'].str.capitalize().value_counts(ascending=True)[-17:]


x.plot(kind='barh')
ax = x.plot(kind='barh', figsize=(30, 20), color='#86bf91', zorder=2, width=0.85)

# Despine
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_visible(False)

# Switch off ticks
ax.tick_params(axis="both", which="both", bottom="off", top="off", labelbottom="on", left="off", right="off", labelleft="on")

# Draw vertical axis lines
vals = ax.get_xticks()
for tick in vals:
    ax.axvline(x=tick, linestyle='dashed', alpha=0.4, color='#eeeeee', zorder=1)

# Set x-axis label
ax.set_xlabel("Number of entries", labelpad=20, weight='bold', size=18)

# Set y-axis label
ax.set_ylabel("Name", labelpad=20, weight='bold', size=18)

# Format y-axis label
ax.xaxis.set_major_formatter(StrMethodFormatter('{x:,g}'))


ax.figure.savefig('test_top.png',format='png')
我想做两件事:

  • 更改x轴和y轴标签的字体大小,即不是y轴/x轴标题(我知道怎么做),而是实际的标签(即这里的名称1->名称17和数字4->27)

  • 添加在a轴上运行的实际直线。我已经添加了一个屏幕截图来显示我的意思,我将如何绘制一条沿x轴的实际直线(虽然这里只显示了5,10,15,但在图的底部没有实际的直线)

  • 有人能告诉我怎么做吗

  • 更改勾号标签的字体大小:
  • 添加在a轴上运行的实际直线:
  • IIUC您想要查看轴线:只是不要将脊椎的可见性设置为
    False
    ,即注释掉这些线:

    #ax.spines['left'].set_visible(False)
    #ax.spines['bottom'].set_visible(False)
    
    (或将可见性设置为
    True

    #ax.spines['left'].set_visible(False)
    #ax.spines['bottom'].set_visible(False)