pancharts 0.1.0__tar.gz
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.
- pancharts-0.1.0/LICENSE +21 -0
- pancharts-0.1.0/MANIFEST.in +3 -0
- pancharts-0.1.0/PKG-INFO +295 -0
- pancharts-0.1.0/README.md +269 -0
- pancharts-0.1.0/pancharts/__init__.py +77 -0
- pancharts-0.1.0/pancharts/ai_option_modifier.py +160 -0
- pancharts-0.1.0/pancharts/chart_config.py +180 -0
- pancharts-0.1.0/pancharts/core.py +487 -0
- pancharts-0.1.0/pancharts/datasets/city_cnname.csv +3796 -0
- pancharts-0.1.0/pancharts/datasets/city_lnglat.csv +145587 -0
- pancharts-0.1.0/pancharts/datasets/countries_info.csv +251 -0
- pancharts-0.1.0/pancharts/datasets/map_filename.json +645 -0
- pancharts-0.1.0/pancharts/pandas_charts.py +629 -0
- pancharts-0.1.0/pancharts/templates/nb_jupyter_notebook.html +21 -0
- pancharts-0.1.0/pancharts/templates/template.html +71 -0
- pancharts-0.1.0/pancharts/utils.py +187 -0
- pancharts-0.1.0/pancharts.egg-info/PKG-INFO +295 -0
- pancharts-0.1.0/pancharts.egg-info/SOURCES.txt +21 -0
- pancharts-0.1.0/pancharts.egg-info/dependency_links.txt +1 -0
- pancharts-0.1.0/pancharts.egg-info/requires.txt +2 -0
- pancharts-0.1.0/pancharts.egg-info/top_level.txt +1 -0
- pancharts-0.1.0/setup.cfg +4 -0
- pancharts-0.1.0/setup.py +33 -0
pancharts-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Your Name
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pancharts-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pancharts
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python library for generating ECharts visualizations
|
|
5
|
+
Home-page: https://github.com/wisherg/pancharts
|
|
6
|
+
Author: Wang Peng
|
|
7
|
+
Author-email: wangpeng_621@163.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: pandas>=1.0.0
|
|
15
|
+
Requires-Dist: jinja2>=2.11.0
|
|
16
|
+
Dynamic: author
|
|
17
|
+
Dynamic: author-email
|
|
18
|
+
Dynamic: classifier
|
|
19
|
+
Dynamic: description
|
|
20
|
+
Dynamic: description-content-type
|
|
21
|
+
Dynamic: home-page
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
Dynamic: requires-dist
|
|
24
|
+
Dynamic: requires-python
|
|
25
|
+
Dynamic: summary
|
|
26
|
+
|
|
27
|
+
# Pancharts
|
|
28
|
+
|
|
29
|
+
A Python library for generating beautiful ECharts visualizations with seamless pandas integration.
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- **Seamless Pandas Integration**: Directly visualize pandas Series and DataFrames without manual data transformation
|
|
34
|
+
- **Simple Data-to-Chart Mapping**: Intuitive API that maps pandas data structures to appropriate chart types
|
|
35
|
+
- **Rich Chart Types**: 20+ chart types including bar, line, scatter, pie, funnel, wordcloud, sunburst, treemap, tree, bar3d, graph, sankey, heatmap, parallel, radar, calendar, and map
|
|
36
|
+
- **AI-Powered Configuration**: Use `modify_option()` and `patch_option()` to modify chart configurations with large language models
|
|
37
|
+
- **Customizable Chart Options**: Full control over ECharts options with deep merge support
|
|
38
|
+
- **Dual Rendering Methods**:
|
|
39
|
+
- `render()`: Save as standalone HTML file
|
|
40
|
+
- `render_notebook()`: Display directly in Jupyter Notebook
|
|
41
|
+
- **Flexible ECharts Sources**: Support for both local and online ECharts CDNs
|
|
42
|
+
- **Map Visualization**: Built-in support for map charts with geographic data
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install pancharts
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Quick Start
|
|
51
|
+
|
|
52
|
+
## Pandas Data Structure to Chart Mapping
|
|
53
|
+
|
|
54
|
+
Pancharts provides specialized classes that automatically map pandas data structures to appropriate visualizations:
|
|
55
|
+
|
|
56
|
+
### 1. `k_v`: Single-Column Index Series
|
|
57
|
+
|
|
58
|
+
Use for pandas Series with a single-level index.
|
|
59
|
+
|
|
60
|
+
**Supported Chart Types:**
|
|
61
|
+
- `bar()` - Bar chart
|
|
62
|
+
- `line()` - Line chart
|
|
63
|
+
- `scatter()` - Scatter chart
|
|
64
|
+
- `escatter()` - Effect scatter chart
|
|
65
|
+
- `pie()` - Pie chart
|
|
66
|
+
- `funnel()` - Funnel chart
|
|
67
|
+
- `wordcloud()` - Word cloud chart
|
|
68
|
+
- `calendar()` - Calendar heatmap
|
|
69
|
+
- `map(map_name)` - Map chart (requires map_name parameter)
|
|
70
|
+
|
|
71
|
+
**Example:**
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import pandas as pd
|
|
75
|
+
from pancharts import k_v
|
|
76
|
+
|
|
77
|
+
# Create sample data
|
|
78
|
+
data = pd.Series(
|
|
79
|
+
[120, 200, 150, 80, 70, 110, 130],
|
|
80
|
+
index=['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
81
|
+
name='Weekly Sales'
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
# Create a bar chart
|
|
85
|
+
chart = k_v(data).bar()
|
|
86
|
+
chart.render()
|
|
87
|
+
|
|
88
|
+
#Displays the chart directly in a Jupyter Notebook cell.
|
|
89
|
+
chart.render_notebook()
|
|
90
|
+
|
|
91
|
+
# Create a pie chart
|
|
92
|
+
chart = k_v(data).pie()
|
|
93
|
+
chart.render()
|
|
94
|
+
|
|
95
|
+
# Create a map chart (special parameter requirement)
|
|
96
|
+
map_data = pd.Series(
|
|
97
|
+
[100, 200, 150, 180],
|
|
98
|
+
index=['湖南省', '上海市', '江西省', '江苏省']
|
|
99
|
+
)
|
|
100
|
+
chart = k_v(map_data).map("china")
|
|
101
|
+
chart.render()
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 2. `km_nv`: Multi-Column Index Series
|
|
105
|
+
|
|
106
|
+
Use for pandas Series with multi-level (hierarchical) indexes.
|
|
107
|
+
|
|
108
|
+
**Supported Chart Types:**
|
|
109
|
+
- `sunburst()` - Sunburst chart
|
|
110
|
+
- `treemap(num=None)` - Treemap chart (optional num parameter to select root)
|
|
111
|
+
- `tree(num=None)` - Tree chart (optional num parameter to select root)
|
|
112
|
+
|
|
113
|
+
**Example:**
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
import pandas as pd
|
|
117
|
+
from pancharts import km_nv
|
|
118
|
+
|
|
119
|
+
# Create multi-index data
|
|
120
|
+
index = pd.MultiIndex.from_product(
|
|
121
|
+
[['Electronics', 'Clothing'], ['Phones', 'Laptops', 'Shirts', 'Pants']]
|
|
122
|
+
)
|
|
123
|
+
data = pd.Series([500, 800, 300, 400,500, 800, 300, 400], index=index)
|
|
124
|
+
chart = km_nv(data).sunburst()
|
|
125
|
+
chart.render()
|
|
126
|
+
|
|
127
|
+
# Create a treemap chart with specific root
|
|
128
|
+
chart = km_nv(data).treemap(num=0)
|
|
129
|
+
chart.render()
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### 3. `k2_nv`: Two-Level Index Series
|
|
133
|
+
|
|
134
|
+
Use for pandas Series with exactly two levels of indexes. Perfect for relationship data.
|
|
135
|
+
|
|
136
|
+
**Supported Chart Types:**
|
|
137
|
+
- `bar3d()` - 3D bar chart
|
|
138
|
+
- `graph()` - Graph/network chart
|
|
139
|
+
- `sankey()` - Sankey diagram
|
|
140
|
+
- `heatmap()` - Heatmap
|
|
141
|
+
|
|
142
|
+
**Special Parameter for `graph()`:**
|
|
143
|
+
The `k2_nv` constructor accepts an optional `cate` parameter (list of length 2) for node categorization.
|
|
144
|
+
|
|
145
|
+
**Example:**
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
import pandas as pd
|
|
149
|
+
from pancharts import k2_nv
|
|
150
|
+
|
|
151
|
+
# Create two-level index data (often from groupby)
|
|
152
|
+
index = pd.MultiIndex.from_product(
|
|
153
|
+
[['Source A', 'Source B'], ['Target X', 'Target Y', 'Target Z']]
|
|
154
|
+
)
|
|
155
|
+
data = pd.Series([10, 20, 15, 25, 30, 18], index=index)
|
|
156
|
+
|
|
157
|
+
# Create a heatmap
|
|
158
|
+
chart = k2_nv(data).heatmap()
|
|
159
|
+
chart.render()
|
|
160
|
+
|
|
161
|
+
# Create a graph with node categorization
|
|
162
|
+
chart = k2_nv(data, cate=['Sources', 'Targets']).graph()
|
|
163
|
+
chart.render()
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### 4. `k_vm`: Single-Column Index, Multi-Column Values DataFrame
|
|
167
|
+
|
|
168
|
+
Use for pandas DataFrames with single index and multiple value columns.
|
|
169
|
+
|
|
170
|
+
**Supported Chart Types:**
|
|
171
|
+
- `parallel()` - Parallel coordinates chart
|
|
172
|
+
- `radar()` - Radar chart
|
|
173
|
+
- `rect_plot(series_type, encode_x, encode_y)` - Flexible encoding chart
|
|
174
|
+
|
|
175
|
+
**Special Methods for `k_vm`:**
|
|
176
|
+
- `vmap_size(dimension, symbolSize)` - Map dimension values to symbol sizes
|
|
177
|
+
- `vmap_color(dimension, color)` - Map dimension values to colors
|
|
178
|
+
|
|
179
|
+
**Example:**
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
import pandas as pd
|
|
183
|
+
import numpy as np
|
|
184
|
+
from pancharts import k_vm
|
|
185
|
+
|
|
186
|
+
# Create DataFrame with multiple columns
|
|
187
|
+
data = pd.DataFrame(
|
|
188
|
+
np.random.rand(10, 5),
|
|
189
|
+
columns=['Feature A', 'Feature B', 'Feature C', 'Feature D', 'Feature E'],
|
|
190
|
+
index=[f'Sample {i}' for i in range(1, 11)]
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
# Create a parallel coordinates chart
|
|
194
|
+
chart = k_vm(data).parallel()
|
|
195
|
+
chart.render()
|
|
196
|
+
|
|
197
|
+
# Create a flexible encoded chart
|
|
198
|
+
chart = k_vm(data).rect_plot('scatter', encode_x=0, encode_y=1)
|
|
199
|
+
chart.render()
|
|
200
|
+
|
|
201
|
+
# Use visual mapping
|
|
202
|
+
config = k_vm(data).vmap_size(dimension=2, symbolSize=[5, 50])
|
|
203
|
+
chart = k_vm(data).rect_plot('scatter', encode_x=0, encode_y=1, config=config)
|
|
204
|
+
chart.render()
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## AI-Powered Configuration Modification
|
|
208
|
+
|
|
209
|
+
Pancharts provides two methods to modify chart configurations using large language models:
|
|
210
|
+
First, you need to obtain the configuration file path using `get_config_file_path`:
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
from pancharts import get_config_file_path
|
|
214
|
+
|
|
215
|
+
config_path = get_config_file_path()
|
|
216
|
+
print(config_path)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Then modify the following configuration items in the config file:
|
|
220
|
+
|
|
221
|
+
DEFAULT_AI_API_KEY = "" # Your LLM API key, e.g. sk-...
|
|
222
|
+
DEFAULT_AI_BASE_URL = "" # LLM API endpoint, e.g. https://api.openai.com/v1
|
|
223
|
+
DEFAULT_AI_MODEL_NAME = "" # LLM model name, e.g. gpt-4o, deepseek-chat
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
### 1. `patch_option()` - Patch-Based Updates (Recommended)
|
|
227
|
+
|
|
228
|
+
Generates only the changed parts and merges them using deep merge. This is more efficient and preserves existing configuration.
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
from pancharts import Pancharts
|
|
232
|
+
from pancharts import k_v
|
|
233
|
+
|
|
234
|
+
# Create sample data
|
|
235
|
+
data = pd.Series(
|
|
236
|
+
[120, 200, 150, 80, 70, 110, 130],
|
|
237
|
+
index=['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
238
|
+
name='Weekly Sales'
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
# Create a bar chart
|
|
242
|
+
chart = k_v(data).bar()
|
|
243
|
+
|
|
244
|
+
# Modify the entire configuration using AI
|
|
245
|
+
chart.patch_option("Change the color of the pillar to red.")
|
|
246
|
+
chart.render()
|
|
247
|
+
```
|
|
248
|
+
### 2. `modify_option()` - Full Configuration Replacement
|
|
249
|
+
|
|
250
|
+
Generates and replaces the entire chart option.
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
from pancharts import Pancharts
|
|
254
|
+
from pancharts import k_v
|
|
255
|
+
|
|
256
|
+
# Create sample data
|
|
257
|
+
data = pd.Series(
|
|
258
|
+
[120, 200, 150, 80, 70, 110, 130],
|
|
259
|
+
index=['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
260
|
+
name='Weekly Sales'
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
# Create a bar chart
|
|
264
|
+
chart = k_v(data).bar()
|
|
265
|
+
|
|
266
|
+
# Modify the entire configuration using AI
|
|
267
|
+
chart.modify_option("Change the color of the pillar to red.")
|
|
268
|
+
chart.render()
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
## Chart Configuration Options
|
|
273
|
+
|
|
274
|
+
Pancharts supports the full ECharts configuration API. You can pass custom configurations using the `config` parameter in all chart methods:
|
|
275
|
+
|
|
276
|
+
```python
|
|
277
|
+
from pancharts import k_v
|
|
278
|
+
import pandas as pd
|
|
279
|
+
|
|
280
|
+
data = pd.Series([1, 2, 3, 4, 5])
|
|
281
|
+
|
|
282
|
+
# Pass custom ECharts options
|
|
283
|
+
custom_config = {
|
|
284
|
+
"title": {"text": "Custom Title", "left": "center"},
|
|
285
|
+
"tooltip": {"trigger": "axis"},
|
|
286
|
+
"legend": {"top": "bottom"}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
chart = k_v(data).bar(config=custom_config)
|
|
290
|
+
chart.render()
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## License
|
|
294
|
+
|
|
295
|
+
MIT License
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# Pancharts
|
|
2
|
+
|
|
3
|
+
A Python library for generating beautiful ECharts visualizations with seamless pandas integration.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Seamless Pandas Integration**: Directly visualize pandas Series and DataFrames without manual data transformation
|
|
8
|
+
- **Simple Data-to-Chart Mapping**: Intuitive API that maps pandas data structures to appropriate chart types
|
|
9
|
+
- **Rich Chart Types**: 20+ chart types including bar, line, scatter, pie, funnel, wordcloud, sunburst, treemap, tree, bar3d, graph, sankey, heatmap, parallel, radar, calendar, and map
|
|
10
|
+
- **AI-Powered Configuration**: Use `modify_option()` and `patch_option()` to modify chart configurations with large language models
|
|
11
|
+
- **Customizable Chart Options**: Full control over ECharts options with deep merge support
|
|
12
|
+
- **Dual Rendering Methods**:
|
|
13
|
+
- `render()`: Save as standalone HTML file
|
|
14
|
+
- `render_notebook()`: Display directly in Jupyter Notebook
|
|
15
|
+
- **Flexible ECharts Sources**: Support for both local and online ECharts CDNs
|
|
16
|
+
- **Map Visualization**: Built-in support for map charts with geographic data
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install pancharts
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
## Pandas Data Structure to Chart Mapping
|
|
27
|
+
|
|
28
|
+
Pancharts provides specialized classes that automatically map pandas data structures to appropriate visualizations:
|
|
29
|
+
|
|
30
|
+
### 1. `k_v`: Single-Column Index Series
|
|
31
|
+
|
|
32
|
+
Use for pandas Series with a single-level index.
|
|
33
|
+
|
|
34
|
+
**Supported Chart Types:**
|
|
35
|
+
- `bar()` - Bar chart
|
|
36
|
+
- `line()` - Line chart
|
|
37
|
+
- `scatter()` - Scatter chart
|
|
38
|
+
- `escatter()` - Effect scatter chart
|
|
39
|
+
- `pie()` - Pie chart
|
|
40
|
+
- `funnel()` - Funnel chart
|
|
41
|
+
- `wordcloud()` - Word cloud chart
|
|
42
|
+
- `calendar()` - Calendar heatmap
|
|
43
|
+
- `map(map_name)` - Map chart (requires map_name parameter)
|
|
44
|
+
|
|
45
|
+
**Example:**
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import pandas as pd
|
|
49
|
+
from pancharts import k_v
|
|
50
|
+
|
|
51
|
+
# Create sample data
|
|
52
|
+
data = pd.Series(
|
|
53
|
+
[120, 200, 150, 80, 70, 110, 130],
|
|
54
|
+
index=['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
55
|
+
name='Weekly Sales'
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# Create a bar chart
|
|
59
|
+
chart = k_v(data).bar()
|
|
60
|
+
chart.render()
|
|
61
|
+
|
|
62
|
+
#Displays the chart directly in a Jupyter Notebook cell.
|
|
63
|
+
chart.render_notebook()
|
|
64
|
+
|
|
65
|
+
# Create a pie chart
|
|
66
|
+
chart = k_v(data).pie()
|
|
67
|
+
chart.render()
|
|
68
|
+
|
|
69
|
+
# Create a map chart (special parameter requirement)
|
|
70
|
+
map_data = pd.Series(
|
|
71
|
+
[100, 200, 150, 180],
|
|
72
|
+
index=['湖南省', '上海市', '江西省', '江苏省']
|
|
73
|
+
)
|
|
74
|
+
chart = k_v(map_data).map("china")
|
|
75
|
+
chart.render()
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 2. `km_nv`: Multi-Column Index Series
|
|
79
|
+
|
|
80
|
+
Use for pandas Series with multi-level (hierarchical) indexes.
|
|
81
|
+
|
|
82
|
+
**Supported Chart Types:**
|
|
83
|
+
- `sunburst()` - Sunburst chart
|
|
84
|
+
- `treemap(num=None)` - Treemap chart (optional num parameter to select root)
|
|
85
|
+
- `tree(num=None)` - Tree chart (optional num parameter to select root)
|
|
86
|
+
|
|
87
|
+
**Example:**
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
import pandas as pd
|
|
91
|
+
from pancharts import km_nv
|
|
92
|
+
|
|
93
|
+
# Create multi-index data
|
|
94
|
+
index = pd.MultiIndex.from_product(
|
|
95
|
+
[['Electronics', 'Clothing'], ['Phones', 'Laptops', 'Shirts', 'Pants']]
|
|
96
|
+
)
|
|
97
|
+
data = pd.Series([500, 800, 300, 400,500, 800, 300, 400], index=index)
|
|
98
|
+
chart = km_nv(data).sunburst()
|
|
99
|
+
chart.render()
|
|
100
|
+
|
|
101
|
+
# Create a treemap chart with specific root
|
|
102
|
+
chart = km_nv(data).treemap(num=0)
|
|
103
|
+
chart.render()
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 3. `k2_nv`: Two-Level Index Series
|
|
107
|
+
|
|
108
|
+
Use for pandas Series with exactly two levels of indexes. Perfect for relationship data.
|
|
109
|
+
|
|
110
|
+
**Supported Chart Types:**
|
|
111
|
+
- `bar3d()` - 3D bar chart
|
|
112
|
+
- `graph()` - Graph/network chart
|
|
113
|
+
- `sankey()` - Sankey diagram
|
|
114
|
+
- `heatmap()` - Heatmap
|
|
115
|
+
|
|
116
|
+
**Special Parameter for `graph()`:**
|
|
117
|
+
The `k2_nv` constructor accepts an optional `cate` parameter (list of length 2) for node categorization.
|
|
118
|
+
|
|
119
|
+
**Example:**
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
import pandas as pd
|
|
123
|
+
from pancharts import k2_nv
|
|
124
|
+
|
|
125
|
+
# Create two-level index data (often from groupby)
|
|
126
|
+
index = pd.MultiIndex.from_product(
|
|
127
|
+
[['Source A', 'Source B'], ['Target X', 'Target Y', 'Target Z']]
|
|
128
|
+
)
|
|
129
|
+
data = pd.Series([10, 20, 15, 25, 30, 18], index=index)
|
|
130
|
+
|
|
131
|
+
# Create a heatmap
|
|
132
|
+
chart = k2_nv(data).heatmap()
|
|
133
|
+
chart.render()
|
|
134
|
+
|
|
135
|
+
# Create a graph with node categorization
|
|
136
|
+
chart = k2_nv(data, cate=['Sources', 'Targets']).graph()
|
|
137
|
+
chart.render()
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 4. `k_vm`: Single-Column Index, Multi-Column Values DataFrame
|
|
141
|
+
|
|
142
|
+
Use for pandas DataFrames with single index and multiple value columns.
|
|
143
|
+
|
|
144
|
+
**Supported Chart Types:**
|
|
145
|
+
- `parallel()` - Parallel coordinates chart
|
|
146
|
+
- `radar()` - Radar chart
|
|
147
|
+
- `rect_plot(series_type, encode_x, encode_y)` - Flexible encoding chart
|
|
148
|
+
|
|
149
|
+
**Special Methods for `k_vm`:**
|
|
150
|
+
- `vmap_size(dimension, symbolSize)` - Map dimension values to symbol sizes
|
|
151
|
+
- `vmap_color(dimension, color)` - Map dimension values to colors
|
|
152
|
+
|
|
153
|
+
**Example:**
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
import pandas as pd
|
|
157
|
+
import numpy as np
|
|
158
|
+
from pancharts import k_vm
|
|
159
|
+
|
|
160
|
+
# Create DataFrame with multiple columns
|
|
161
|
+
data = pd.DataFrame(
|
|
162
|
+
np.random.rand(10, 5),
|
|
163
|
+
columns=['Feature A', 'Feature B', 'Feature C', 'Feature D', 'Feature E'],
|
|
164
|
+
index=[f'Sample {i}' for i in range(1, 11)]
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
# Create a parallel coordinates chart
|
|
168
|
+
chart = k_vm(data).parallel()
|
|
169
|
+
chart.render()
|
|
170
|
+
|
|
171
|
+
# Create a flexible encoded chart
|
|
172
|
+
chart = k_vm(data).rect_plot('scatter', encode_x=0, encode_y=1)
|
|
173
|
+
chart.render()
|
|
174
|
+
|
|
175
|
+
# Use visual mapping
|
|
176
|
+
config = k_vm(data).vmap_size(dimension=2, symbolSize=[5, 50])
|
|
177
|
+
chart = k_vm(data).rect_plot('scatter', encode_x=0, encode_y=1, config=config)
|
|
178
|
+
chart.render()
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## AI-Powered Configuration Modification
|
|
182
|
+
|
|
183
|
+
Pancharts provides two methods to modify chart configurations using large language models:
|
|
184
|
+
First, you need to obtain the configuration file path using `get_config_file_path`:
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from pancharts import get_config_file_path
|
|
188
|
+
|
|
189
|
+
config_path = get_config_file_path()
|
|
190
|
+
print(config_path)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Then modify the following configuration items in the config file:
|
|
194
|
+
|
|
195
|
+
DEFAULT_AI_API_KEY = "" # Your LLM API key, e.g. sk-...
|
|
196
|
+
DEFAULT_AI_BASE_URL = "" # LLM API endpoint, e.g. https://api.openai.com/v1
|
|
197
|
+
DEFAULT_AI_MODEL_NAME = "" # LLM model name, e.g. gpt-4o, deepseek-chat
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
### 1. `patch_option()` - Patch-Based Updates (Recommended)
|
|
201
|
+
|
|
202
|
+
Generates only the changed parts and merges them using deep merge. This is more efficient and preserves existing configuration.
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
from pancharts import Pancharts
|
|
206
|
+
from pancharts import k_v
|
|
207
|
+
|
|
208
|
+
# Create sample data
|
|
209
|
+
data = pd.Series(
|
|
210
|
+
[120, 200, 150, 80, 70, 110, 130],
|
|
211
|
+
index=['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
212
|
+
name='Weekly Sales'
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
# Create a bar chart
|
|
216
|
+
chart = k_v(data).bar()
|
|
217
|
+
|
|
218
|
+
# Modify the entire configuration using AI
|
|
219
|
+
chart.patch_option("Change the color of the pillar to red.")
|
|
220
|
+
chart.render()
|
|
221
|
+
```
|
|
222
|
+
### 2. `modify_option()` - Full Configuration Replacement
|
|
223
|
+
|
|
224
|
+
Generates and replaces the entire chart option.
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
from pancharts import Pancharts
|
|
228
|
+
from pancharts import k_v
|
|
229
|
+
|
|
230
|
+
# Create sample data
|
|
231
|
+
data = pd.Series(
|
|
232
|
+
[120, 200, 150, 80, 70, 110, 130],
|
|
233
|
+
index=['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
234
|
+
name='Weekly Sales'
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
# Create a bar chart
|
|
238
|
+
chart = k_v(data).bar()
|
|
239
|
+
|
|
240
|
+
# Modify the entire configuration using AI
|
|
241
|
+
chart.modify_option("Change the color of the pillar to red.")
|
|
242
|
+
chart.render()
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
## Chart Configuration Options
|
|
247
|
+
|
|
248
|
+
Pancharts supports the full ECharts configuration API. You can pass custom configurations using the `config` parameter in all chart methods:
|
|
249
|
+
|
|
250
|
+
```python
|
|
251
|
+
from pancharts import k_v
|
|
252
|
+
import pandas as pd
|
|
253
|
+
|
|
254
|
+
data = pd.Series([1, 2, 3, 4, 5])
|
|
255
|
+
|
|
256
|
+
# Pass custom ECharts options
|
|
257
|
+
custom_config = {
|
|
258
|
+
"title": {"text": "Custom Title", "left": "center"},
|
|
259
|
+
"tooltip": {"trigger": "axis"},
|
|
260
|
+
"legend": {"top": "bottom"}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
chart = k_v(data).bar(config=custom_config)
|
|
264
|
+
chart.render()
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## License
|
|
268
|
+
|
|
269
|
+
MIT License
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Pancharts - A Python library for generating ECharts visualizations
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .core import Pancharts
|
|
9
|
+
from .pandas_charts import k_v, km_nv, k2_nv, k_vm
|
|
10
|
+
from .utils import (
|
|
11
|
+
add_quotes_to_keys,
|
|
12
|
+
random_color,
|
|
13
|
+
random_color_list,
|
|
14
|
+
get_index_type,
|
|
15
|
+
get_value_type,
|
|
16
|
+
deep_merge,
|
|
17
|
+
load_city_cnname,
|
|
18
|
+
load_city_lnglat,
|
|
19
|
+
load_countries_info
|
|
20
|
+
)
|
|
21
|
+
from .chart_config import (
|
|
22
|
+
BAR_OPTION,
|
|
23
|
+
LINE_OPTION,
|
|
24
|
+
SCATTER_OPTION,
|
|
25
|
+
ESCATTER_OPTION,
|
|
26
|
+
PIE_OPTION,
|
|
27
|
+
FUNNEL_OPTION,
|
|
28
|
+
WORDCLOUD_OPTION,
|
|
29
|
+
SUNBURST_OPTION,
|
|
30
|
+
TREEMAP_OPTION,
|
|
31
|
+
TREE_OPTION,
|
|
32
|
+
BAR3D_OPTION,
|
|
33
|
+
GRAPH_OPTION,
|
|
34
|
+
SANKEY_OPTION,
|
|
35
|
+
HEATMAP_OPTION,
|
|
36
|
+
PARALLEL_OPTION,
|
|
37
|
+
RADAR_OPTION,
|
|
38
|
+
CALENDAR_OPTION
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
__version__ = "0.1.0"
|
|
42
|
+
__author__ = "Wang Peng"
|
|
43
|
+
__email__ = "wangpeng_621@163.com"
|
|
44
|
+
|
|
45
|
+
__all__ = [
|
|
46
|
+
"Pancharts",
|
|
47
|
+
"k_v",
|
|
48
|
+
"km_nv",
|
|
49
|
+
"k2_nv",
|
|
50
|
+
"k_vm",
|
|
51
|
+
"add_quotes_to_keys",
|
|
52
|
+
"random_color",
|
|
53
|
+
"random_color_list",
|
|
54
|
+
"get_index_type",
|
|
55
|
+
"get_value_type",
|
|
56
|
+
"deep_merge",
|
|
57
|
+
"load_city_cnname",
|
|
58
|
+
"load_city_lnglat",
|
|
59
|
+
"load_countries_info",
|
|
60
|
+
"BAR_OPTION",
|
|
61
|
+
"LINE_OPTION",
|
|
62
|
+
"SCATTER_OPTION",
|
|
63
|
+
"ESCATTER_OPTION",
|
|
64
|
+
"PIE_OPTION",
|
|
65
|
+
"FUNNEL_OPTION",
|
|
66
|
+
"WORDCLOUD_OPTION",
|
|
67
|
+
"SUNBURST_OPTION",
|
|
68
|
+
"TREEMAP_OPTION",
|
|
69
|
+
"TREE_OPTION",
|
|
70
|
+
"BAR3D_OPTION",
|
|
71
|
+
"GRAPH_OPTION",
|
|
72
|
+
"SANKEY_OPTION",
|
|
73
|
+
"HEATMAP_OPTION",
|
|
74
|
+
"PARALLEL_OPTION",
|
|
75
|
+
"RADAR_OPTION",
|
|
76
|
+
"CALENDAR_OPTION"
|
|
77
|
+
]
|