以一种美观的方式绘制43个不同类别的频率

我根据训练集中每个类别的频率创建了以下直方图

enter image description here

每个类别的标签太长,类似于

Speed limit (20km/h)

我可以将每个标签放在条形上吗?


回答:

也许像这样?

enter image description here

import numpy as npimport matplotlib.pyplot as pltN=5xlabel = ["Speed limit ("+str(i)+"km/h)" for i in range(0,N)]xs = np.arange(0,7,1.5)ys = [8,6,10,7,9]width = 0.3*np.ones(N)fig, ax = plt.subplots()bars = ax.bar(xs, ys, width, color='k',alpha=0.3)plt.xticks(xs, xlabel,rotation=270)for i,bar in enumerate(bars):    height = bar.get_height()    ax.text(bar.get_x() + bar.get_width()/2., 0.1*height,                '%s' % xlabel[i],rotation=90,ha='center', va='bottom')plt.show()

将其更改为水平条形图:

enter image description here

import numpy as npimport matplotlib.pyplot as pltN = 5xlabel = ["Speed limit ("+str(i)+"km/h)" for i in range(0,5)]xs = np.arange(0,5)/2ys = [8,6,10,7,9]width = 0.3*np.ones(N)fig, ax = plt.subplots()bars = ax.barh(xs, ys, width, color='k',alpha=0.3)plt.xticks([])for i,bar in enumerate(bars):    height = bar.get_height()    ax.text(bar.get_x()+3, bar.get_y()+bar.get_height()/3,                '%s' % xlabel[i],rotation=0,ha='center', va='bottom')plt.tight_layout()plt.show()

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注