moderne-visualizations-misc 0.60.0__py3-none-any.whl → 0.62.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,162 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "from code_data_science import data_table as dt\n",
10
+ "\n",
11
+ "df = dt.read_csv(\"../samples/dependency_usage_violin.csv\")"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": null,
17
+ "metadata": {},
18
+ "outputs": [],
19
+ "source": [
20
+ "df = df[[\"artifactId\", \"version\", \"depth\"]]"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": null,
26
+ "metadata": {},
27
+ "outputs": [],
28
+ "source": [
29
+ "from code_data_science.versions import index as index_versions\n",
30
+ "\n",
31
+ "# make sure version is a string\n",
32
+ "df[\"version\"] = df[\"version\"].astype(str)\n",
33
+ "\n",
34
+ "vmap = index_versions(df.version)\n",
35
+ "df[\"nVersion\"] = list(map(lambda v: vmap[v], df.version))\n",
36
+ "\n",
37
+ "\n",
38
+ "def index_ga(groupartifacts):\n",
39
+ " sorted_ga = sorted(list(set(groupartifacts)))\n",
40
+ " return {ga: sorted_ga.index(ga) for ga in sorted_ga}\n",
41
+ "\n",
42
+ "\n",
43
+ "gmap = index_ga(df.artifactId)\n",
44
+ "df[\"nArtifactId\"] = list(map(lambda g: gmap[g], df.artifactId))\n",
45
+ "\n",
46
+ "df = df.sort_values(by=[\"nVersion\", \"nArtifactId\"])"
47
+ ]
48
+ },
49
+ {
50
+ "cell_type": "code",
51
+ "execution_count": null,
52
+ "metadata": {},
53
+ "outputs": [],
54
+ "source": [
55
+ "import plotly.graph_objects as go\n",
56
+ "import code_data_science.palette as palette\n",
57
+ "\n",
58
+ "colors = palette.colors_by_weight(500)\n",
59
+ "\n",
60
+ "fig = go.Figure()\n",
61
+ "\n",
62
+ "# Add a trace to the plot for each category\n",
63
+ "for i, category in enumerate(df[\"nArtifactId\"].unique()):\n",
64
+ " category_data = df[df[\"nArtifactId\"] == category]\n",
65
+ "\n",
66
+ " # Calculate counts for each dependency and version combination\n",
67
+ " counts = (\n",
68
+ " category_data.groupby(\"nVersion\")[\"nArtifactId\"]\n",
69
+ " .count()\n",
70
+ " .reset_index(name=\"count\")\n",
71
+ " )\n",
72
+ "\n",
73
+ " category_data_with_counts = category_data.merge(counts, on=\"nVersion\")\n",
74
+ "\n",
75
+ " # Generate hover text including the count information\n",
76
+ " hover_text = category_data_with_counts.apply(\n",
77
+ " lambda row: f'<b>Artifact</b>: {row[\"artifactId\"]}<br><b>Version</b>: {row[\"version\"]}<br><b>Count</b>: {row[\"count\"]}',\n",
78
+ " axis=1,\n",
79
+ " )\n",
80
+ "\n",
81
+ " fig.add_trace(\n",
82
+ " go.Scatter(\n",
83
+ " x=category_data[\"nArtifactId\"],\n",
84
+ " y=category_data[\"nVersion\"],\n",
85
+ " mode=\"markers\",\n",
86
+ " marker=dict(color=colors[i % len(colors)], size=8),\n",
87
+ " showlegend=False,\n",
88
+ " name=\"\",\n",
89
+ " text=hover_text,\n",
90
+ " hoverinfo=\"text\",\n",
91
+ " hoverlabel=dict(font=dict(size=18)),\n",
92
+ " )\n",
93
+ " )\n",
94
+ "\n",
95
+ " fig.add_trace(\n",
96
+ " go.Violin(\n",
97
+ " x=category_data[\"nArtifactId\"],\n",
98
+ " y=category_data[\"nVersion\"],\n",
99
+ " fillcolor=\"black\",\n",
100
+ " opacity=0.15,\n",
101
+ " line_color=\"black\",\n",
102
+ " showlegend=False,\n",
103
+ " width=0.7,\n",
104
+ " bandwidth=0.4,\n",
105
+ " hoverinfo=\"none\",\n",
106
+ " hoveron=\"points\",\n",
107
+ " )\n",
108
+ " )\n",
109
+ "\n",
110
+ "num_versions = df[\"nVersion\"].nunique()\n",
111
+ "height_per_version = 32\n",
112
+ "width_per_dependency = 80\n",
113
+ "fig_height = max(num_versions * height_per_version, 900)\n",
114
+ "fig_width = max(len(list(gmap.values())) * width_per_dependency, 900)\n",
115
+ "tick_font_size = 13\n",
116
+ "# Customizing the layout\n",
117
+ "fig.update_layout(\n",
118
+ " title=\"Artifact versions in use\",\n",
119
+ " xaxis_title=\"Artifacts\",\n",
120
+ " yaxis_title=\"Versions\",\n",
121
+ " height=fig_height,\n",
122
+ " width=fig_width,\n",
123
+ " xaxis=dict(\n",
124
+ " tickfont=dict(size=tick_font_size),\n",
125
+ " tickmode=\"array\",\n",
126
+ " tickvals=list(gmap.values()),\n",
127
+ " ticktext=list(gmap.keys()),\n",
128
+ " ),\n",
129
+ " yaxis=dict(\n",
130
+ " tickfont=dict(size=tick_font_size),\n",
131
+ " tickmode=\"array\",\n",
132
+ " tickvals=list(vmap.values()),\n",
133
+ " ticktext=list(vmap.keys()),\n",
134
+ " ),\n",
135
+ ")\n",
136
+ "\n",
137
+ "fig.show()"
138
+ ]
139
+ }
140
+ ],
141
+ "metadata": {
142
+ "kernelspec": {
143
+ "display_name": "Python 3",
144
+ "language": "python",
145
+ "name": "python3"
146
+ },
147
+ "language_info": {
148
+ "codemirror_mode": {
149
+ "name": "ipython",
150
+ "version": 3
151
+ },
152
+ "file_extension": ".py",
153
+ "mimetype": "text/x-python",
154
+ "name": "python",
155
+ "nbconvert_exporter": "python",
156
+ "pygments_lexer": "ipython3",
157
+ "version": "3.11.4"
158
+ }
159
+ },
160
+ "nbformat": 4,
161
+ "nbformat_minor": 2
162
+ }