Python 增加y轴和x轴标签的字体(不是y轴和x轴标题)
我有一个要绘制的数据框,数据框(下面代码中的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
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')
我想做两件事:
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)