Как заголовок, я в настоящее время рисую 4 радиолокационные карты на 1 рис. И сталкиваюсь с этой проблемой: некоторые части моих меток xtick находятся внутри графика и затрудняют чтение.
Как вы можете видеть здесь,xlabel в правом нижнем углу (трифторуксусный ангидрид) не может быть прочитан четко. 1
Как переместить метку xtick наружу?
Вот мой код ((1-я часть немного запутанная, поскольку вы можете просто скопировать вставку вЧтобы воспроизвести график, я должен был создать весь кадр данных с нуля, а не вызывать read_csv.))
Я создал ax1 ax2 ax3 ax4, они все одинаковые, поэтому вы можете игнорировать ax2-4
data = pd.DataFrame({
'1. materials': np.array(['Chloropyrazine', 'NH2NH2', 'Propanol', 'DMSO', 'Heptane',
"Meldrum's acid", 'HCl', 'IPEA', 'Pivaloyl chloride',
'Trifluoroacetic anhydride ', '2,4,5-Trifluorophenylacetic acid',
'TFA', 'PrNH2', '10M NaOH', 'Brine', 'IPAc', 'H2O',
'Dichloromethane', 'Phosphoric acid', 'Ethanol', 'Hydrogen']),
'GWP100 (year)': np.array([ 1.25600000e+01, 3.23000000e+00, 1.10000000e-01,
3.21000000e+00, 6.00000000e-02, 1.80000000e+00,
5.05000000e+00, 1.09000000e+00, 1.04000000e+00,
1.63600000e+01, 3.50000000e-01, 2.80000000e-01,
1.88000000e+00, 4.00000000e-02, 0.00000000e+00,
2.70000000e+00, 1.00000000e-02, 7.60000000e-01,
1.62000000e+00, 2.10000000e-01, 1.00000000e-02]),
'ODP (year)': np.array([ 7.88000000e+00, 3.88000000e+00, 3.00000000e-02,
2.04000000e+00, 1.40000000e-01, 3.30000000e-01,
5.72000000e+00, 3.50000000e-01, 2.90000000e-01,
1.76000000e+01, 7.00000000e-02, 3.30000000e-01,
3.50000000e-01, 8.00000000e-02, 0.00000000e+00,
8.80000000e-01, 0.00000000e+00, 5.58100000e+01,
6.40000000e-01, 1.00000000e-02, 1.00000000e-02]),
'POFP (year)': np.array([ 1.46500000e+01, 3.78000000e+00, 4.80000000e-01,
4.59000000e+00, 3.50000000e-01, 3.59000000e+00,
6.85000000e+00, 3.00000000e+00, 1.53000000e+00,
2.28400000e+01, 7.20000000e-01, 4.00000000e-01,
2.82000000e+00, 6.00000000e-02, 0.00000000e+00,
7.45000000e+00, 1.00000000e-02, 1.55000000e+00,
3.53000000e+00, 4.50000000e-01, 1.00000000e-02]),
'TAP (year)': np.array([ 1.60300000e+01, 4.77000000e+00, 1.60000000e-01,
4.08000000e+00, 1.40000000e-01, 2.28000000e+00,
8.71000000e+00, 1.42000000e+00, 1.63000000e+00,
2.69000000e+01, 4.00000000e-01, 4.70000000e-01,
2.15000000e+00, 6.00000000e-02, 0.00000000e+00,
3.52000000e+00, 1.00000000e-02, 1.42000000e+00,
6.80000000e+00, 2.20000000e-01, 1.00000000e-02])
})
#%%
number = len(data)
my_label = list(data[data.columns[0]])
#%%
#np.random.seed(223)
np.random.seed(165)
fig1 = plt.figure(1, figsize = (16,13))
# to draw the figure and set some parameters
ax1 = fig1.add_subplot(3,2,1, polar = True)
ax1.set_theta_offset(np.pi / 2)
ax1.set_theta_direction(-1)
theta = np.linspace(0.0, 2 * np.pi, number, endpoint=False)
radii_1 = data[data.columns[1]]
width = 0.7
bars_1 = ax1.bar(theta, radii_1, width, bottom =0, label = my_label)
# to assign colors
for_color_number_range = np.random.uniform(0, 1, size= len(data))
for bar, color_number in zip(bars_1, for_color_number_range):
bar.set_facecolor(plt.cm.tab20( color_number))
bar.set_alpha(0.8)
# =============================================================================
# set x axis, and last one overlaps the 1st one so we eliminate it
# =============================================================================
divide_angles = np.linspace(0.0, 2 * np.pi, 8)
divide_angles = divide_angles[:-1]
ax1.set_xticks(divide_angles)
ax1.set_xticklabels(np.array(['Chloropyrazine', 'DMSO', 'HCl', 'Trifluoroacetic\nanhydride ',
'PrNH2', 'IPAc', 'Phosphoric\nacid']))# =============================================================================
# set y axis
# =============================================================================
ax1.set_yticks([10,20,30,40])
ax1.set_yticklabels(['10%', '20%', '30%', '40%',],fontsize = 8)
ax1.set_ylim(0,50)
# =============================================================================
# 設定title
# =============================================================================
ax1.set_title('\n\nGWP\n', loc = 'left')
# ax2
ax2 = fig1.add_subplot(3,2,2, polar = True)
ax2.set_theta_offset(np.pi / 2)
ax2.set_theta_direction(-1)
radii_2 = data[data.columns[2]]
bars_2 = ax2.bar(theta, radii_2, width, bottom =0, label = my_label)
for bar, color_number in zip(bars_2, for_color_number_range):
bar.set_facecolor(plt.cm.tab20( color_number))
bar.set_alpha(0.8)
ax2.set_xticks(divide_angles)
ax2.set_xticklabels(np.array(['Chloropyrazine', 'DMSO', 'HCl', 'Trifluoroacetic\nanhydride ',
'PrNH2', 'IPAc', 'Phosphoric\nacid']))
ax2.set_yticks([10,20,30,40])
ax2.set_yticklabels(['10%', '20%', '30%', '40%',],fontsize = 8)
ax2.set_ylim(0,50)
ax2.set_title('\n\nFDP\n', loc = 'left')
# ax3
ax3 = fig1.add_subplot(3,2,3, polar = True)
ax3.set_theta_offset(np.pi / 2)
ax3.set_theta_direction(-1)
radii_3 = data[data.columns[3]]
bars_3 = ax3.bar(theta, radii_3, width, bottom =0, label = my_label)
for bar, color_number in zip(bars_3, for_color_number_range):
bar.set_facecolor(plt.cm.tab20( color_number))
bar.set_alpha(0.8)
ax3.set_xticks(divide_angles)
ax3.set_xticklabels(np.array(['Chloropyrazine', 'DMSO', 'HCl', 'Trifluoroacetic\nanhydride ',
'PrNH2', 'IPAc', 'Phosphoric\nacid']))
ax3.set_yticks([10,20,30,40])
ax3.set_yticklabels(['10%', '20%', '30%', '40%',],fontsize = 8)
ax3.set_ylim(0,50)
ax3.set_title('\n\nFEP\n', loc = 'left')
# ax4
ax4 = fig1.add_subplot(3,2,4, polar = True)
ax4.set_theta_offset(np.pi / 2)
ax4.set_theta_direction(-1)
radii_4 = data[data.columns[4]]
bars_4 = ax4.bar(theta, radii_4, width, bottom =0, label = my_label)
for bar, color_number in zip(bars_4, for_color_number_range):
bar.set_facecolor(plt.cm.tab20( color_number))
bar.set_alpha(0.8)
ax4.set_xticks(divide_angles)
ax4.set_xticklabels(np.array(['Chloropyrazine', 'DMSO', 'HCl', 'Trifluoroacetic\nanhydride ',
'PrNH2', 'IPAc', 'Phosphoric\nacid']))
ax4.set_yticks([10,20,30,40])
ax4.set_yticklabels(['10%', '20%', '30%', '40%',],fontsize = 8)
ax4.set_ylim(0,50)
ax4.set_title('\n\nHTP\n', loc = 'left')
# =============================================================================
#
# =============================================================================
my_legend = fig1.legend(bars_1, my_label, loc = 'lower center', facecolor='black', ncol = 4, bbox_to_anchor=(0.5,0))
for text in my_legend.get_texts():
text.set_color("White")
fig1.tight_layout()