2024-09-29 23:16:54 发布
网友
我有一个字典,里面有7191个键,这些值表示每个键的频率。在
7191
degree_distri = {'F2': 102, 'EGFR': 23, 'C1R': 20,...}
为了绘制直方图,我做了:
但我收到了一条错误信息: unsupported operand type(s) for -: 'str' and 'float'
unsupported operand type(s) for -: 'str' and 'float'
我应该不使用上面的代码来绘制柱状图吗?如果没有,有什么建议?为什么会导致错误呢?在
谢谢你!在
^{}作为强制性参数,两个标量序列:条形左侧的x坐标和钢筋的高度。因此,您应该使用^{{cd2>}获取所需的参数,然后使用^{}设置所需的记号:
import matplotlib.pyplot as plt degree_distri = {'F2': 102, 'EGFR': 23, 'C1R': 20} keys, values = degree_distri.keys(), degree_distri.values() plt.bar(range(len(values)), values, color='r') plt.xticks(range(len(values)), keys) plt.show()
看看这个例子here和documentation你必须 以不同的格式提供数据。在
import matplotlib.pyplot as plt import numpy as np degree_distri = {'F2': 102, 'EGFR': 23, 'C1R': 20} fig, ax = plt.subplots() indices = np.arange(len(degree_distri)) width = 0.6 ax.bar(indices, degree_distri.values(), width) ax.set_xticks(indices) ax.set_xticklabels(degree_distri.keys())
{{0}的数组{。然后提供值。必须将dict中的keys设置为轴标签,并且要将轴标签放置在正确的位置,必须使用条的x位置调用set_xticks。在
dict
keys
set_xticks
^{} 作为强制性参数,两个标量序列:条形左侧的x坐标和钢筋的高度。因此,您应该使用^{{cd2>}获取所需的参数,然后使用^{} 设置所需的记号:
看看这个例子here和documentation你必须 以不同的格式提供数据。在
{{0}的数组{。然后提供值。必须将
dict
中的keys
设置为轴标签,并且要将轴标签放置在正确的位置,必须使用条的x位置调用set_xticks
。在相关问题 更多 >
编程相关推荐