递减计数的可视化

问题描述 投票:0回答:2

我有一个看起来像这样的数据框:

    components       non_breaking_count breaking_count
0   paths-modified              22956   8640
1   endpoints-modified          22155   8149
2   endpoints-added              8109   5354
3   paths-added                  7375   4787
4   info-version                 5680   857
5   components-schemas-added     2555   1597
6   info-description             1940   762
7   tags-added                   1031   564
8   info-title                   859    551
9   servers-added                711    332
10  info-termsOfService          701    161
11  servers-deleted              609    262
12  components-schemas-deleted   588    938
13  components-securitySchemes   301    112
14  tags-modified                297    128
15  components-securitySchemes  229     171
16  components-parameters-added 209     239
17  tags-deleted                199     541
18  components-responses-added  183     164
19  info-contact-name           153     96
20  security-added              140     121
21  info-contact-email          132     110
22  servers-modified            120     32
23  info-license-name           115     46
24  info-license-url            105     36
25  paths-deleted                97     4979
26  info-contact-url             93     51
27  components-securitySchemes-deleted  87  71
28  endpoints-deleted            84     5612

我一直在寻找一种好方法来通过它们的计数和注释(对于所有组件列)来可视化它。我正在寻找的是一张用于破坏的图表和另一张用于不破坏的图表。

我脑子里有一个切片条形图,有两个条形分别代表

breaking
non breaking
,但是拟合 28 个值有点困难,所以我不得不放弃这个选项。我也尝试在
echarts
中使用夜莺图表,但比例不知何故不匹配。另一种方式是
treemap
,但是我希望避免那种和
pie chart

有人对我可以使用哪种类型的图表有效地可视化这些数据有任何建议吗?

python graph plotly visualization echarts
2个回答
0
投票

你可以试试 bar of pie.

您可以将示例中给出的年龄替换为您集合中较低的数据。


-1
投票

考虑到您拥有的组件数量 (28),在保持可读性的同时将所有组件放入一个图形中可能具有挑战性。但是,您可以结合使用可视化效果来有效地表示您的数据。

这里有一个可视化中断和非中断组件数量递减的建议:

  1. Horizontal Bar Chart:使用水平条形图来表示组件的递减计数。每个条形代表一个组件,条形的长度对应于计数。您可以为中断和非中断计数创建单独的条形图。

  2. Top-N 条形图:为了应对拟合所有组件的挑战,您可以考虑创建“Top-N”条形图。选择计数最高的前 N 个组件,并在图表中将它们可视化。这将使您能够专注于最重要的组件,同时仍然捕获整体分布。

  3. 附加信息:要将组件名称包含为注释,您可以显示组件名称及其相应的条。这可以通过用组件名称标记每个条形或通过在条形图旁边提供单独的注释列表来实现。

以下是使用 Python 中的

matplotlib
库为中断计数创建水平条形图的示例代码片段:

import matplotlib.pyplot as plt
import pandas as pd

# Assuming your data is stored in a DataFrame named 'df'

# Sort the dataframe by breaking count in descending order
sorted_df = df.sort_values('breaking_count', ascending=False)

# Select the top N components to visualize
top_n = 10
top_n_df = sorted_df.head(top_n)

# Create the bar chart
fig, ax = plt.subplots()
ax.barh(top_n_df['components'], top_n_df['breaking_count'])

# Add labels to the bars
for i, v in enumerate(top_n_df['breaking_count']):
    ax.text(v, i, str(v), ha='left', va='center')

# Set labels and title
ax.set_xlabel('Breaking Count')
ax.set_ylabel('Components')
ax.set_title('Top 10 Components by Breaking Count')

# Display the chart
plt.show()

您也可以将此代码调整为不间断计数。

通过结合使用前 N 个方法、条形图和注释,您可以有效地可视化组件的递减计数,同时突出显示最重要的组件。调整

top_n
的值以满足您的需要并确保图表的可读性。

© www.soinside.com 2019 - 2024. All rights reserved.