|
1 | | -""" pyplots.ai |
| 1 | +"""pyplots.ai |
2 | 2 | bubble-packed: Basic Packed Bubble Chart |
3 | | -Library: highcharts unknown | Python 3.13.11 |
4 | | -Quality: 90/100 | Created: 2025-12-23 |
| 3 | +Library: highcharts 1.10.3 | Python 3.14.3 |
| 4 | +Quality: /100 | Updated: 2026-02-23 |
5 | 5 | """ |
6 | 6 |
|
7 | 7 | import tempfile |
|
17 | 17 |
|
18 | 18 |
|
19 | 19 | # Data - Company market share by sector |
20 | | -# Packed bubbles group by sector with size representing market value |
21 | 20 | data = [ |
22 | | - # Technology sector |
23 | 21 | { |
24 | 22 | "name": "Technology", |
25 | 23 | "data": [ |
|
30 | 28 | {"name": "Cybersecurity", "value": 280}, |
31 | 29 | ], |
32 | 30 | }, |
33 | | - # Finance sector |
34 | 31 | { |
35 | 32 | "name": "Finance", |
36 | 33 | "data": [ |
|
40 | 37 | {"name": "Fintech", "value": 260}, |
41 | 38 | ], |
42 | 39 | }, |
43 | | - # Healthcare sector |
44 | 40 | { |
45 | 41 | "name": "Healthcare", |
46 | 42 | "data": [ |
|
50 | 46 | {"name": "Healthcare Services", "value": 240}, |
51 | 47 | ], |
52 | 48 | }, |
53 | | - # Energy sector |
54 | 49 | { |
55 | 50 | "name": "Energy", |
56 | 51 | "data": [ |
|
59 | 54 | {"name": "Utilities", "value": 290}, |
60 | 55 | ], |
61 | 56 | }, |
62 | | - # Consumer sector |
63 | 57 | { |
64 | 58 | "name": "Consumer", |
65 | 59 | "data": [ |
|
72 | 66 | ] |
73 | 67 |
|
74 | 68 | # Colorblind-safe palette for sectors |
75 | | -colors = ["#306998", "#FFD43B", "#9467BD", "#17BECF", "#8C564B"] |
| 69 | +colors = ["#306998", "#E5A02E", "#9467BD", "#17BECF", "#8C564B"] |
76 | 70 |
|
77 | 71 | # Create chart |
78 | 72 | chart = Chart(container="container") |
79 | 73 | chart.options = HighchartsOptions() |
80 | 74 |
|
81 | 75 | # Chart configuration |
82 | | -chart.options.chart = {"type": "packedbubble", "width": 4800, "height": 2700, "backgroundColor": "#ffffff"} |
| 76 | +chart.options.chart = { |
| 77 | + "type": "packedbubble", |
| 78 | + "width": 4800, |
| 79 | + "height": 2700, |
| 80 | + "backgroundColor": "#ffffff", |
| 81 | + "margin": [100, 50, 100, 50], |
| 82 | +} |
83 | 83 |
|
84 | 84 | # Title |
85 | 85 | chart.options.title = { |
86 | | - "text": "bubble-packed · Market Sectors · highcharts · pyplots.ai", |
| 86 | + "text": "bubble-packed \u00b7 highcharts \u00b7 pyplots.ai", |
87 | 87 | "style": {"fontSize": "64px", "fontWeight": "bold"}, |
88 | 88 | } |
89 | 89 |
|
90 | 90 | # Subtitle |
91 | | -chart.options.subtitle = {"text": "Circle size represents market value ($B)", "style": {"fontSize": "36px"}} |
| 91 | +chart.options.subtitle = {"text": "Market value by sector ($B)", "style": {"fontSize": "36px", "color": "#666666"}} |
92 | 92 |
|
93 | 93 | # Tooltip |
94 | 94 | chart.options.tooltip = { |
|
103 | 103 | # Plot options for packed bubble |
104 | 104 | chart.options.plot_options = { |
105 | 105 | "packedbubble": { |
106 | | - "minSize": "60%", |
107 | | - "maxSize": "180%", |
| 106 | + "minSize": "80%", |
| 107 | + "maxSize": "250%", |
108 | 108 | "zMin": 0, |
109 | 109 | "zMax": 1000, |
110 | 110 | "layoutAlgorithm": { |
111 | | - "gravitationalConstant": 0.02, |
| 111 | + "gravitationalConstant": 0.05, |
112 | 112 | "splitSeries": False, |
113 | 113 | "seriesInteraction": True, |
114 | 114 | "dragBetweenSeries": False, |
|
117 | 117 | "dataLabels": { |
118 | 118 | "enabled": True, |
119 | 119 | "format": "{point.name}", |
120 | | - "filter": {"property": "y", "operator": ">", "value": 230}, |
| 120 | + "filter": {"property": "y", "operator": ">", "value": 260}, |
121 | 121 | "style": {"fontSize": "28px", "fontWeight": "bold", "color": "white", "textOutline": "2px contrast"}, |
122 | 122 | }, |
123 | 123 | } |
|
126 | 126 | # Add series with colors |
127 | 127 | series_list = [] |
128 | 128 | for i, sector in enumerate(data): |
129 | | - series_config = { |
130 | | - "type": "packedbubble", |
131 | | - "name": sector["name"], |
132 | | - "data": sector["data"], |
133 | | - "color": colors[i % len(colors)], |
134 | | - } |
135 | | - series_list.append(series_config) |
| 129 | + series_list.append( |
| 130 | + {"type": "packedbubble", "name": sector["name"], "data": sector["data"], "color": colors[i % len(colors)]} |
| 131 | + ) |
136 | 132 |
|
137 | 133 | chart.options.series = series_list |
138 | 134 |
|
139 | 135 | # Download Highcharts JS and highcharts-more.js for packed bubble support |
140 | | -highcharts_url = "https://code.highcharts.com/highcharts.js" |
141 | | -highcharts_more_url = "https://code.highcharts.com/highcharts-more.js" |
| 136 | +highcharts_url = "https://cdn.jsdelivr.net/npm/highcharts/highcharts.js" |
| 137 | +highcharts_more_url = "https://cdn.jsdelivr.net/npm/highcharts/highcharts-more.js" |
142 | 138 |
|
143 | 139 | with urllib.request.urlopen(highcharts_url, timeout=30) as response: |
144 | 140 | highcharts_js = response.read().decode("utf-8") |
|
167 | 163 | <html> |
168 | 164 | <head> |
169 | 165 | <meta charset="utf-8"> |
170 | | - <script src="https://code.highcharts.com/highcharts.js"></script> |
171 | | - <script src="https://code.highcharts.com/highcharts-more.js"></script> |
| 166 | + <script src="https://cdn.jsdelivr.net/npm/highcharts/highcharts.js"></script> |
| 167 | + <script src="https://cdn.jsdelivr.net/npm/highcharts/highcharts-more.js"></script> |
172 | 168 | </head> |
173 | 169 | <body style="margin:0;"> |
174 | 170 | <div id="container" style="width: 100%; height: 100vh;"></div> |
|
191 | 187 |
|
192 | 188 | driver = webdriver.Chrome(options=chrome_options) |
193 | 189 | driver.get(f"file://{temp_path}") |
194 | | -time.sleep(5) # Wait for chart to render |
| 190 | +time.sleep(5) |
195 | 191 | driver.save_screenshot("plot_raw.png") |
196 | 192 | driver.quit() |
197 | 193 |
|
|
201 | 197 | img_cropped.save("plot.png") |
202 | 198 | Path("plot_raw.png").unlink() |
203 | 199 |
|
204 | | -Path(temp_path).unlink() # Clean up temp file |
| 200 | +Path(temp_path).unlink() |
0 commit comments