3 回答

TA贡献1820条经验 获得超9个赞
您可以执行以下操作:
>>> scores = sorted( [(name, float(val)) for val, name in scores], key=lambda x:x[1], reverse=True ) >>> plt.bar(*zip(*scores))

TA贡献1828条经验 获得超3个赞
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
scores = np.array([
(18.0, 'bill'), (23.0, 'sarah'), (12.0, 'stacy'),
(71.0, 'joe'), (54.0, 'adam'), (87.0, 'kat'),
(46.0, 'le'), (87.0, 'dave'), (89.0, 'kara')])
scores_df = pd.DataFrame(scores, columns=["score", "name"])
scores_df.score = scores_df["score"].astype(float)
scores_df.sort_values("score", ascending=False, inplace=True)
scores_df.plot.bar(x="name", y="score")
输出:

TA贡献1895条经验 获得超3个赞
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
x=[]
y=[]
for i in range(len(array)):
x.append(array[i][0])
y.append(array[i][1])
plt.bar(y,x, align='center', alpha=0.5)
plt.ylabel('name')
plt.xlabel('number')
plt.title('name/number')
plt.show()
添加回答
举报