Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何按升序或降序对matplotlib图形进行排序?_Python_Matplotlib - Fatal编程技术网

Python 如何按升序或降序对matplotlib图形进行排序?

Python 如何按升序或降序对matplotlib图形进行排序?,python,matplotlib,Python,Matplotlib,结果是没有任何次序的随机图。谢谢你的帮助 importances = selector_clf.feature_importances_ std = np.std([tree.feature_importances_ for tree in selector_clf.estimators_], axis=0) fig, ax = plt.subplots() plt.rcParams["figure.figsize"] = [14,15] plt.b


结果是没有任何次序的随机图。谢谢你的帮助

importances = selector_clf.feature_importances_
std = np.std([tree.feature_importances_ for tree in 
selector_clf.estimators_],
         axis=0)

fig, ax = plt.subplots()


plt.rcParams["figure.figsize"] = [14,15]
plt.barh(range(len(predictors_tree)),std, color='lightgreen')
plt.ylabel("Predictors")
plt.xlabel("Importance")
plt.title("Importance Score")
plt.yticks(range(len(predictors_tree)), predictors_tree)
plt.show()

不同的特征重要性没有直接分类;您必须手动对它们进行排序。这可以使用
np.sort
(和
np.argsort
,以便根据特征重要性标准偏差对预测树进行排序)。下面的代码应该可以做到这一点

importances=selector\u clf.feature\u importances_
std=np.std([tree.feature\u importances\u用于树中
选择器\u clf.估计器\u],
轴=0)
#获取已排序的std和排序索引,并对预测树进行排序
标准排序=np.排序(标准)
排序索引=np.argsort(标准)
预测器树=[排序索引中s的预测器树]
图,ax=plt.子批次()
plt.rcParams[“figure.figsize”]=[14,15]
plt.barh(范围(len(预测器树)),标准排序,颜色为淡绿色)
plt.ylabel(“预测因子”)
plt.xlabel(“重要性”)
项目名称(“重要性评分”)
plt.yticks(范围(len(预测器树)),预测器树)
plt.show()

看起来你们的轴并不相互依赖,所以我会在plt.barh之前对你们的std阵列进行排序

这些文件提供:


其中一个应该适用于升序,然后可以用于降序。

数据是什么样子的?这个图表是什么样子的?请创建我刚刚上传的图片链接。请查看该帖子的链接。谢谢谢谢你,莱纳德!这个函数似乎起作用了,但它并没有将它从最高的STDDEV分类到最低的STDDEV。请看我随信附上的图片。有一个链接。谢谢是的,这确实是我的猜测。我提供给您的代码实际上会起作用。
a = np.array([[1,4],[3,1]])
np.sort(a)                # sort along the last axis

#array([[1, 4],
#       [1, 3]])

np.sort(a, axis=None)     # sort the flattened array

#array([1, 1, 3, 4])

np.sort(a, axis=0)        # sort along the first axis

#array([[1, 1],
#       [3, 4]])