Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.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 如何显示可视化的值_Python_Matplotlib_Visualization - Fatal编程技术网

Python 如何显示可视化的值

Python 如何显示可视化的值,python,matplotlib,visualization,Python,Matplotlib,Visualization,这是我的可视化条形图的源代码。我用我的数据作图。但我需要做一个关于价值的展示 但我不知道。我怎么做 bar_width = 0.4 alpha = 0.5 value_dic = visualization_missing(df_train) value_data = [] label_data = [] count = 5 for i in range (count): value_data.append(value_dic[i][0]) label_data.appen

这是我的可视化条形图的源代码。我用我的数据作图。但我需要做一个关于价值的展示

但我不知道。我怎么做

bar_width = 0.4
alpha = 0.5

value_dic = visualization_missing(df_train)

value_data = []
label_data = []
count = 5

for i in range (count):
    value_data.append(value_dic[i][0])
    label_data.append(value_dic[i][1])

index = np.arange(count)
    
p_train = plt.bar(index , value_data , bar_width, color = 'b', alpha = alpha , label = 'Train')

# get number of count missing value in test set by features
value_dic_test = visualization_missing(df_test)

value_data_test = []
label_data_test = []
count = 5

for i in range (count):
    value_data_test.append(value_dic[i][0])
    label_data_test.append(value_dic[i][1])

index = np.arange(count)

p_test = plt.bar(index + bar_width , value_data_test , bar_width , color = 'r' , alpha = alpha , label = 'Test')

#visualization numebr of train,test missing value 
plt.title = ('Missing Value in Train set & Test set')
plt.ylabe = ("Number of missing value")
plt.xlabe = ("Feature")
plt.xticks(index, label_data, fontsize = 10)
plt.legend((p_train[0], p_test[0]),('Training','Test'), fontsize = 10)

    
plt.show()

然后是用于可视化的数据集

[(1456, 'PoolQC'),
 (1408, 'MiscFeature'),
 (1352, 'Alley'),
 (1169, 'Fence'),
 (730, 'FireplaceQu'),
 (227, 'LotFrontage'),
 (78, 'GarageCond'),
 (76, 'GarageType'),
 (45, 'BsmtCond'),
 (44, 'BsmtExposure'),
 (42, 'BsmtFinType2'),
 (16, 'MasVnrType'),
 (15, 'MasVnrArea'),
 (4, 'MSZoning'),
 (2, 'Functional'),
 (1, 'SaleType')]

如何在条形图上显示值?

中有一个很好的示例,其中条形图的返回坐标用于注释条形图:

def autolabel(rects):
    """Attach a text label above each bar in *rects*, displaying its height."""
    for rect in rects:
        height = rect.get_height()
        ax.annotate('{}'.format(height),
                    xy=(rect.get_x() + rect.get_width() / 2, height),
                    xytext=(0, 3),  # 3 points vertical offset
                    textcoords="offset points",
                    ha='center', va='bottom')

p_test = plt.bar(index + bar_width , value_data_test , [...])
autolabel(p_test)