Skip to content

Commit 4825983

Browse files
committed
fix bug
1 parent d465236 commit 4825983

13 files changed

Lines changed: 2310 additions & 687 deletions

File tree

README.md

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,47 @@
1-
# 概况
1+
# 目录
2+
3+
* [项目概况](https://github.com/chenjiandongx/pyecharts/blob/master/README.md#项目概况)
4+
* [如何安装](https://github.com/chenjiandongx/pyecharts/blob/master/README.md#如何安装)
5+
* [开始使用](https://github.com/chenjiandongx/pyecharts/blob/master/README.md#开始使用)
6+
* [通用配置项](https://github.com/chenjiandongx/pyecharts/blob/master/README.md#通用配置项)
7+
* xyAxis:直角坐标系中的 x、y 轴(Line、Bar、Scatter、EffectScatter)
8+
* legend:图例组件。图例组件展现了不同系列的标记(symbol),颜色和名字。可以通过点击图例控制哪些系列不显示。
9+
* label:图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。
10+
* lineStyle:带线图形的线的风格选项(Line、Polar、Radar、Graph、Parallel)
11+
* [图表详细](https://github.com/chenjiandongx/pyecharts/blob/master/README.md#图表详细)
12+
* [ar(柱状图/条形图)
13+
* EffectScatter(带有涟漪特效动画的散点图)
14+
* Funnel(漏斗图)
15+
* Gauge(仪表盘)
16+
* Geo(地理坐标系)
17+
* Graph(关系图)
18+
* Line(折线/面积图)
19+
* Liquid(水球图)
20+
* Map(地图)
21+
* Parallel(平行坐标系)
22+
* Pie(饼图)
23+
* Polar(极坐标系)
24+
* Radar(雷达图)
25+
* Scatter(散点图)
26+
* WordCloud(词云图)
27+
* [用户自定义](https://github.com/chenjiandongx/pyecharts/blob/master/README.md#用户自定义)
28+
* [更多示例](https://github.com/chenjiandongx/pyecharts/blob/master/README.md#更多示例)
29+
* [关于项目](https://github.com/chenjiandongx/pyecharts/blob/master/README.md#关于项目)
30+
31+
32+
# 项目概况
233
pyecharts 是一个用于生成 Echarts 图表的类库。
334

435
[Echarts](https://github.com/ecomfe/echarts) 是百度开源的一个数据可视化 JS 库。看了官方的介绍文档,觉得很不错,就想看看有没有人实现了 Python 库可以直接调用的。Github 上找到了一个 [echarts-python](https://github.com/yufeiminds/echarts-python) 不过这个项目已经很久没更新且也没什么介绍文档。借鉴了该项目,就自己动手实现一个,于是就有了 pyecharts。API 接口是从另外一个图表库 [pygal](https://github.com/Kozea/pygal) 中模仿的。
536

637

7-
# 安装
8-
pyecharts 兼容 Python2 和 Python3。Version 0.1.2
38+
# 如何安装
39+
pyecharts 兼容 Python2 和 Python3。Current version 0.1.2
940
```python
1041
pip install pyecharts
1142
```
1243

13-
# 使用
44+
# 开始使用
1445
首先开始来绘制你的第一个图表
1546
```python
1647
from pyecharts import Bar
@@ -112,7 +143,10 @@ legend:图例组件。图例组件展现了不同系列的标记(symbol),颜
112143
* legend_orient -> str
113144
图例列表的布局朝向,默认为'horizontal',有'horizontal', 'vertical'可选
114145
* legend_pos -> str
115-
图例位置,默认为'center',有'left', 'center', 'right'可选
146+
图例组件离容器左侧的距离,默认为'center',有'left', 'center', 'right'可选
147+
* legend_top -> str
148+
图例组件离容器上侧的距离,默认为'top',有'top', 'center', 'bottom'可选
149+
116150

117151
label:图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。
118152

@@ -891,14 +925,19 @@ add(name, data, angle_data=None, radius_data=None, type='line', symbol_size=4, s
891925
数据堆叠,同个类目轴上系列配置相同的 stack 值可以堆叠放置
892926
* axis_range -> list
893927
坐标轴刻度范围。默认值为 [None, None]
928+
* is_angleaxis_show -> bool
929+
是否显示极坐标系的角度轴,默认为 True
930+
* is_radiusaxis_show -> bool
931+
是否显示极坐标系的径向轴,默认为 True
894932

895933
```python
896934
from pyecharts import Polar
897935

898936
import random
899937
data = [(i, random.randint(1, 100)) for i in range(101)]
900938
polar = Polar("极坐标系-散点图示例")
901-
polar.add("", data, boundary_gap=False, type='scatter', is_splitline_show=False, is_axisline_show=True)
939+
polar.add("", data, boundary_gap=False, type='scatter', is_splitline_show=False,
940+
area_color=None, is_axisline_show=True)
902941
polar.show_config()
903942
polar.render()
904943
```
@@ -908,6 +947,10 @@ polar.render()
908947
是否显示分割线,默认为 True
909948
* is_axisline_show -> bool
910949
是否显示坐标轴线,默认为 True
950+
* area_opacity -> float
951+
填充区域透明度
952+
* area_color -> str
953+
填充区域颜色
911954

912955
**Tip:** 可配置 **lineStyle** 参数
913956

@@ -1214,7 +1257,9 @@ bar.render()
12141257
# 更多示例
12151258

12161259
* 更多示例请参考 [example.md](https://github.com/chenjiandongx/pyecharts/blob/master/example.md)
1260+
* 欢迎大家补充
12171261

1218-
# 最后
1262+
# 关于项目
12191263

1220-
* 欢迎大家使用及提出意见
1264+
* 欢迎大家使用及提出意见
1265+
* // Todo

example.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ polar.render()
1818
```
1919
![example-0](https://github.com/chenjiandongx/pyecharts/blob/master/images/example-0.png)
2020

21+
2122
用极坐标系画出一朵小花
2223
```python
2324
import math
@@ -35,6 +36,26 @@ polar.render()
3536
```
3637
![example-1](https://github.com/chenjiandongx/pyecharts/blob/master/images/example-1.png)
3738

39+
40+
还可以给小花涂上颜色
41+
```python
42+
import math
43+
from pyecharts import Polar
44+
45+
data = []
46+
for i in range(361):
47+
t = i / 180 * math.pi
48+
r = math.sin(2 * t) * math.cos(2 * t)
49+
data.append([r, i])
50+
polar = Polar("极坐标系示例", width=1200, height=600)
51+
polar.add("Color-Flower", data, start_angle=0, symbol=None, axis_range=[0, None],
52+
area_color="#f71f24", area_opacity=0.6)
53+
polar.show_config()
54+
polar.render()
55+
```
56+
![example-1-1](https://github.com/chenjiandongx/pyecharts/blob/master/images/example-1-1.png)
57+
58+
3859
用散点图画出一个爱心
3960
```python
4061
from pyecharts import Scatter
@@ -46,6 +67,7 @@ scatter.render()
4667
```
4768
![example-2](https://github.com/chenjiandongx/pyecharts/blob/master/images/example-2.png)
4869

70+
4971
用散点图画出一个火辣的 Bra
5072
```python
5173
from pyecharts import Scatter
@@ -57,6 +79,7 @@ scatter.render()
5779
```
5880
![example-3](https://github.com/chenjiandongx/pyecharts/blob/master/images/example-3.png)
5981

82+
6083
用散点图画出一个性感的 Bra
6184
```python
6285
from pyecharts import Scatter
@@ -68,6 +91,7 @@ scatter.render()
6891
```
6992
![example-4](https://github.com/chenjiandongx/pyecharts/blob/master/images/example-4.png)
7093

94+
7195
某地最低温和最高气温折线图
7296
```python
7397
from pyecharts import Line
@@ -81,6 +105,7 @@ line.render()
81105
```
82106
![example-5](https://github.com/chenjiandongx/pyecharts/blob/master/images/example-5.gif)
83107

108+
84109
饼图嵌套
85110
```python
86111
from pyecharts import Pie
@@ -93,6 +118,7 @@ pie.render()
93118
```
94119
![example-6](https://github.com/chenjiandongx/pyecharts/blob/master/images/example-6.png)
95120

121+
96122
饼图再嵌套
97123
```python
98124
import random
@@ -109,6 +135,7 @@ pie.render()
109135
```
110136
![example-7](https://github.com/chenjiandongx/pyecharts/blob/master/images/example-7.gif)
111137

138+
112139
某地的降水量和蒸发量柱状图
113140
```python
114141
from pyecharts import Bar
@@ -123,3 +150,55 @@ bar.show_config()
123150
bar.render()
124151
```
125152
![example-8](https://github.com/chenjiandongx/pyecharts/blob/master/images/example-8.png)
153+
154+
155+
各类电影中"好片"所占的比例
156+
```python
157+
from pyecharts import Pie
158+
159+
pie = Pie('各类电影中"好片"所占的比例', "数据来着豆瓣", title_pos='center')
160+
pie.add("", ["剧情", ""], [25, 75], center=[10, 30], radius=[18, 24],
161+
label_pos='center', is_label_show=True, label_text_color=None, )
162+
pie.add("", ["奇幻", ""], [24, 76], center=[30, 30], radius=[18, 24],
163+
label_pos='center', is_label_show=True, label_text_color=None, legend_pos='left')
164+
pie.add("", ["爱情", ""], [14, 86], center=[50, 30], radius=[18, 24],
165+
label_pos='center', is_label_show=True, label_text_color=None)
166+
pie.add("", ["惊悚", ""], [11, 89], center=[70, 30], radius=[18, 24],
167+
label_pos='center', is_label_show=True, label_text_color=None)
168+
pie.add("", ["冒险", ""], [27, 73], center=[90, 30], radius=[18, 24],
169+
label_pos='center', is_label_show=True, label_text_color=None)
170+
pie.add("", ["动作", ""], [15, 85], center=[10, 70], radius=[18, 24],
171+
label_pos='center', is_label_show=True, label_text_color=None)
172+
pie.add("", ["喜剧", ""], [54, 46], center=[30, 70], radius=[18, 24],
173+
label_pos='center', is_label_show=True, label_text_color=None)
174+
pie.add("", ["科幻", ""], [26, 74], center=[50, 70], radius=[18, 24],
175+
label_pos='center', is_label_show=True, label_text_color=None)
176+
pie.add("", ["悬疑", ""], [25, 75], center=[70, 70], radius=[18, 24],
177+
label_pos='center', is_label_show=True, label_text_color=None)
178+
pie.add("", ["犯罪", ""], [28, 72], center=[90, 70], radius=[18, 24],
179+
label_pos='center', is_label_show=True, label_text_color=None, is_legend_show=True, legend_top="center")
180+
pie.show_config()
181+
pie.render()
182+
```
183+
![example-9](https://github.com/chenjiandongx/pyecharts/blob/master/images/example-9.png)
184+
185+
186+
用极坐标系画出一个蜗牛壳
187+
```python
188+
import math
189+
from pyecharts import Polar
190+
191+
data = []
192+
for i in range(5):
193+
for j in range(101):
194+
theta = j / 100 * 360
195+
alpha = i * 360 + theta
196+
r = math.pow(math.e, 0.003 * alpha)
197+
data.append([r, theta])
198+
polar = Polar("极坐标系示例")
199+
polar.add("", data, symbol_size=0, symbol='circle', start_angle=-25, is_radiusaxis_show=False,
200+
area_color="#f3c5b3", area_opacity=0.5, is_angleaxis_show=False)
201+
polar.show_config()
202+
polar.render()
203+
```
204+
![example-10](https://github.com/chenjiandongx/pyecharts/blob/master/images/example-10.png)

images/example-1-1.png

66.7 KB
Loading

images/example-10.png

10.2 KB
Loading

images/example-9.png

46.2 KB
Loading

pyecharts/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def add(self, angle_data=None,
8484
geo_normal_color=None,
8585
gravity=None,
8686
interval=None,
87+
is_angleaxis_show=None,
8788
is_area_show=None,
8889
is_axisline_show=None,
8990
is_calculable=None,
@@ -95,6 +96,7 @@ def add(self, angle_data=None,
9596
is_legend_show=None,
9697
is_liquid_animation=None,
9798
is_liquid_outline_show=None,
99+
is_radiusaxis_show=None,
98100
is_random=None,
99101
is_roam=None,
100102
is_rotatelabel=None,
@@ -112,6 +114,7 @@ def add(self, angle_data=None,
112114
layout=None,
113115
legend_orient=None,
114116
legend_pos=None,
117+
legend_top=None,
115118
line_curve=None,
116119
line_opacity=None,
117120
line_type=None,

pyecharts/charts/funnel.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def __add(self, name, attr, value, **kwargs):
3434
_data.append({"name": _name, "value": _value})
3535
for a in attr:
3636
self._option.get('legend').get('data').append(a)
37+
_dset = set(self._option.get('legend').get('data'))
38+
self._option.get('legend').update(data=list(_dset))
3739
self._option.get('series').append({
3840
"type": "funnel",
3941
"name": name,

pyecharts/charts/pie.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def __add(self, name, attr, value,
6464
rosetype = "radius"
6565
for a in attr:
6666
self._option.get('legend').get('data').append(a)
67+
_dset = set(self._option.get('legend').get('data'))
68+
self._option.get('legend').update(data=list(_dset))
6769
self._option.get('series').append({
6870
"type": "pie",
6971
"name": name,

pyecharts/charts/polar.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def __add(self, name, data,
2626
clockwise=True,
2727
is_stack=False,
2828
axis_range=None,
29+
is_angleaxis_show=True,
30+
is_radiusaxis_show=True,
2931
**kwargs):
3032
"""
3133
@@ -56,6 +58,10 @@ def __add(self, name, data,
5658
数据堆叠,同个类目轴上系列配置相同的 stack 值可以堆叠放置
5759
:param axis_range:
5860
坐标轴刻度范围。
61+
:param is_angleaxis_show:
62+
是否显示极坐标系的角度轴,默认为 True
63+
:param is_radiusaxis_show:
64+
是否显示极坐标系的径向轴,默认为 True
5965
:param kwargs:
6066
"""
6167
chart = get_all_options(**kwargs)
@@ -67,6 +73,9 @@ def __add(self, name, data,
6773
if axis_range:
6874
if len(axis_range) == 2:
6975
_amin, _amax = axis_range
76+
_area_style = {"normal": chart['area_style']}
77+
if kwargs.get('area_color', None) is None:
78+
_area_style = None
7079
if type in ("scatter", "line"):
7180
self._option.get('series').append({
7281
"type": type,
@@ -76,6 +85,7 @@ def __add(self, name, data,
7685
"symbolSize": symbol_size,
7786
"data": data,
7887
"label": chart['label'],
88+
"areaStyle": _area_style
7989
})
8090
elif type == "effectScatter":
8191
self._option.get('series').append({
@@ -122,6 +132,7 @@ def __add(self, name, data,
122132
if type not in ("barAngle", "barRadius"):
123133
self._option.update(
124134
angleAxis={
135+
"show":is_angleaxis_show,
125136
"type": polar_type,
126137
"data": angle_data,
127138
"clockwise": clockwise,
@@ -133,6 +144,7 @@ def __add(self, name, data,
133144
)
134145
self._option.update(
135146
radiusAxis={
147+
"show": is_radiusaxis_show,
136148
"type": polar_type,
137149
"data": radius_data,
138150
"min": _amin,

pyecharts/option.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ def legend(type=None,
302302
is_legend_show=True,
303303
legend_orient="horizontal",
304304
legend_pos="center",
305+
legend_top='top',
305306
**kwargs):
306307
""" 图例组件。
307308
图例组件展现了不同系列的标记(symbol),颜色和名字。可以通过点击图例控制哪些系列不显示。
@@ -312,7 +313,9 @@ def legend(type=None,
312313
:param legend_orient:
313314
图例列表的布局朝向,有'horizontal', 'vertical'可选
314315
:param legend_pos:
315-
图例位置,有'left', 'center', 'right'可选
316+
图例组件离容器左侧的距离,有'left', 'center', 'right'可选
317+
:param legend_pos:
318+
图例组件离容器上侧的距离,有'top', 'center', 'bottom'可选
316319
:param kwargs:
317320
:return:
318321
"""
@@ -323,6 +326,7 @@ def legend(type=None,
323326
"selectedMode":selected_mode,
324327
"show": is_legend_show,
325328
"left": legend_pos,
329+
"top": legend_top,
326330
"orient": legend_orient
327331
}
328332
return _legend

0 commit comments

Comments
 (0)