出于某种原因,每当我运行下面的代码时,我都会得到一个值错误:无法将字符串转换为浮点数:'A'
我将逗号更改为下面的小数点,以便长度在轴之间排列。
import numpy as np
import matplotlib.pyplot as plt
plt.rcdefaults()
%matplotlib inline
fig, ax = plt.subplots(1, 1, figsize=(12,9))
ax.spines['top'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
x_axis = 8.6667, 9.5, -8.4, 0, -4, 6
y_axis = 'A','B','C','D','E','F'
ind = np.arange(len(y_axis))
plt.xticks(fontsize=12)
plt.yticks(ind, y_axis, fontsize=14)
plt.tick_params(
axis='x',
which='both',
top='off')
plt.tick_params(
axis='y',
which='both',
right='off',
left='off')
plt.title('Super Awesome Title', fontsize=18, ha='center')
for a, b in zip(y_axis, ind):
plt.text(a, b, str(a), fontsize=16, color='black')
plt.barh(ind, x_axis)