mirror of
https://github.com/pyecharts/pyecharts.git
synced 2025-12-08 20:59:23 +00:00
fix bug
This commit is contained in:
parent
20fbefb562
commit
695a9a5e64
61
README.md
61
README.md
@ -1,16 +1,47 @@
|
||||
# 概况
|
||||
# 目录
|
||||
|
||||
* [项目概况](https://github.com/chenjiandongx/pyecharts/blob/master/README.md#项目概况)
|
||||
* [如何安装](https://github.com/chenjiandongx/pyecharts/blob/master/README.md#如何安装)
|
||||
* [开始使用](https://github.com/chenjiandongx/pyecharts/blob/master/README.md#开始使用)
|
||||
* [通用配置项](https://github.com/chenjiandongx/pyecharts/blob/master/README.md#通用配置项)
|
||||
* xyAxis:直角坐标系中的 x、y 轴(Line、Bar、Scatter、EffectScatter)
|
||||
* legend:图例组件。图例组件展现了不同系列的标记(symbol),颜色和名字。可以通过点击图例控制哪些系列不显示。
|
||||
* label:图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。
|
||||
* lineStyle:带线图形的线的风格选项(Line、Polar、Radar、Graph、Parallel)
|
||||
* [图表详细](https://github.com/chenjiandongx/pyecharts/blob/master/README.md#图表详细)
|
||||
* [ar(柱状图/条形图)
|
||||
* EffectScatter(带有涟漪特效动画的散点图)
|
||||
* Funnel(漏斗图)
|
||||
* Gauge(仪表盘)
|
||||
* Geo(地理坐标系)
|
||||
* Graph(关系图)
|
||||
* Line(折线/面积图)
|
||||
* Liquid(水球图)
|
||||
* Map(地图)
|
||||
* Parallel(平行坐标系)
|
||||
* Pie(饼图)
|
||||
* Polar(极坐标系)
|
||||
* Radar(雷达图)
|
||||
* Scatter(散点图)
|
||||
* WordCloud(词云图)
|
||||
* [用户自定义](https://github.com/chenjiandongx/pyecharts/blob/master/README.md#用户自定义)
|
||||
* [更多示例](https://github.com/chenjiandongx/pyecharts/blob/master/README.md#更多示例)
|
||||
* [关于项目](https://github.com/chenjiandongx/pyecharts/blob/master/README.md#关于项目)
|
||||
|
||||
|
||||
# 项目概况
|
||||
pyecharts 是一个用于生成 Echarts 图表的类库。
|
||||
|
||||
[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) 中模仿的。
|
||||
|
||||
|
||||
# 安装
|
||||
pyecharts 兼容 Python2 和 Python3。Version 0.1.2
|
||||
# 如何安装
|
||||
pyecharts 兼容 Python2 和 Python3。Current version 0.1.2
|
||||
```python
|
||||
pip install pyecharts
|
||||
```
|
||||
|
||||
# 使用
|
||||
# 开始使用
|
||||
首先开始来绘制你的第一个图表
|
||||
```python
|
||||
from pyecharts import Bar
|
||||
@ -112,7 +143,10 @@ legend:图例组件。图例组件展现了不同系列的标记(symbol),颜
|
||||
* legend_orient -> str
|
||||
图例列表的布局朝向,默认为'horizontal',有'horizontal', 'vertical'可选
|
||||
* legend_pos -> str
|
||||
图例位置,默认为'center',有'left', 'center', 'right'可选
|
||||
图例组件离容器左侧的距离,默认为'center',有'left', 'center', 'right'可选
|
||||
* legend_top -> str
|
||||
图例组件离容器上侧的距离,默认为'top',有'top', 'center', 'bottom'可选
|
||||
|
||||
|
||||
label:图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等。
|
||||
|
||||
@ -891,6 +925,10 @@ add(name, data, angle_data=None, radius_data=None, type='line', symbol_size=4, s
|
||||
数据堆叠,同个类目轴上系列配置相同的 stack 值可以堆叠放置
|
||||
* axis_range -> list
|
||||
坐标轴刻度范围。默认值为 [None, None]。
|
||||
* is_angleaxis_show -> bool
|
||||
是否显示极坐标系的角度轴,默认为 True
|
||||
* is_radiusaxis_show -> bool
|
||||
是否显示极坐标系的径向轴,默认为 True
|
||||
|
||||
```python
|
||||
from pyecharts import Polar
|
||||
@ -898,7 +936,8 @@ from pyecharts import Polar
|
||||
import random
|
||||
data = [(i, random.randint(1, 100)) for i in range(101)]
|
||||
polar = Polar("极坐标系-散点图示例")
|
||||
polar.add("", data, boundary_gap=False, type='scatter', is_splitline_show=False, is_axisline_show=True)
|
||||
polar.add("", data, boundary_gap=False, type='scatter', is_splitline_show=False,
|
||||
area_color=None, is_axisline_show=True)
|
||||
polar.show_config()
|
||||
polar.render()
|
||||
```
|
||||
@ -908,6 +947,10 @@ polar.render()
|
||||
是否显示分割线,默认为 True
|
||||
* is_axisline_show -> bool
|
||||
是否显示坐标轴线,默认为 True
|
||||
* area_opacity -> float
|
||||
填充区域透明度
|
||||
* area_color -> str
|
||||
填充区域颜色
|
||||
|
||||
**Tip:** 可配置 **lineStyle** 参数
|
||||
|
||||
@ -1214,7 +1257,9 @@ bar.render()
|
||||
# 更多示例
|
||||
|
||||
* 更多示例请参考 [example.md](https://github.com/chenjiandongx/pyecharts/blob/master/example.md)
|
||||
* 欢迎大家补充
|
||||
|
||||
# 最后
|
||||
# 关于项目
|
||||
|
||||
* 欢迎大家使用及提出意见
|
||||
* 欢迎大家使用及提出意见
|
||||
* // Todo
|
||||
79
example.md
79
example.md
@ -18,6 +18,7 @@ polar.render()
|
||||
```
|
||||

|
||||
|
||||
|
||||
用极坐标系画出一朵小花
|
||||
```python
|
||||
import math
|
||||
@ -35,6 +36,26 @@ polar.render()
|
||||
```
|
||||

|
||||
|
||||
|
||||
还可以给小花涂上颜色
|
||||
```python
|
||||
import math
|
||||
from pyecharts import Polar
|
||||
|
||||
data = []
|
||||
for i in range(361):
|
||||
t = i / 180 * math.pi
|
||||
r = math.sin(2 * t) * math.cos(2 * t)
|
||||
data.append([r, i])
|
||||
polar = Polar("极坐标系示例", width=1200, height=600)
|
||||
polar.add("Color-Flower", data, start_angle=0, symbol=None, axis_range=[0, None],
|
||||
area_color="#f71f24", area_opacity=0.6)
|
||||
polar.show_config()
|
||||
polar.render()
|
||||
```
|
||||

|
||||
|
||||
|
||||
用散点图画出一个爱心
|
||||
```python
|
||||
from pyecharts import Scatter
|
||||
@ -46,6 +67,7 @@ scatter.render()
|
||||
```
|
||||

|
||||
|
||||
|
||||
用散点图画出一个火辣的 Bra
|
||||
```python
|
||||
from pyecharts import Scatter
|
||||
@ -57,6 +79,7 @@ scatter.render()
|
||||
```
|
||||

|
||||
|
||||
|
||||
用散点图画出一个性感的 Bra
|
||||
```python
|
||||
from pyecharts import Scatter
|
||||
@ -68,6 +91,7 @@ scatter.render()
|
||||
```
|
||||

|
||||
|
||||
|
||||
某地最低温和最高气温折线图
|
||||
```python
|
||||
from pyecharts import Line
|
||||
@ -81,6 +105,7 @@ line.render()
|
||||
```
|
||||

|
||||
|
||||
|
||||
饼图嵌套
|
||||
```python
|
||||
from pyecharts import Pie
|
||||
@ -93,6 +118,7 @@ pie.render()
|
||||
```
|
||||

|
||||
|
||||
|
||||
饼图再嵌套
|
||||
```python
|
||||
import random
|
||||
@ -109,6 +135,7 @@ pie.render()
|
||||
```
|
||||

|
||||
|
||||
|
||||
某地的降水量和蒸发量柱状图
|
||||
```python
|
||||
from pyecharts import Bar
|
||||
@ -123,3 +150,55 @@ bar.show_config()
|
||||
bar.render()
|
||||
```
|
||||

|
||||
|
||||
|
||||
各类电影中"好片"所占的比例
|
||||
```python
|
||||
from pyecharts import Pie
|
||||
|
||||
pie = Pie('各类电影中"好片"所占的比例', "数据来着豆瓣", title_pos='center')
|
||||
pie.add("", ["剧情", ""], [25, 75], center=[10, 30], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None, )
|
||||
pie.add("", ["奇幻", ""], [24, 76], center=[30, 30], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None, legend_pos='left')
|
||||
pie.add("", ["爱情", ""], [14, 86], center=[50, 30], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None)
|
||||
pie.add("", ["惊悚", ""], [11, 89], center=[70, 30], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None)
|
||||
pie.add("", ["冒险", ""], [27, 73], center=[90, 30], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None)
|
||||
pie.add("", ["动作", ""], [15, 85], center=[10, 70], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None)
|
||||
pie.add("", ["喜剧", ""], [54, 46], center=[30, 70], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None)
|
||||
pie.add("", ["科幻", ""], [26, 74], center=[50, 70], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None)
|
||||
pie.add("", ["悬疑", ""], [25, 75], center=[70, 70], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None)
|
||||
pie.add("", ["犯罪", ""], [28, 72], center=[90, 70], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None, is_legend_show=True, legend_top="center")
|
||||
pie.show_config()
|
||||
pie.render()
|
||||
```
|
||||

|
||||
|
||||
|
||||
用极坐标系画出一个蜗牛壳
|
||||
```python
|
||||
import math
|
||||
from pyecharts import Polar
|
||||
|
||||
data = []
|
||||
for i in range(5):
|
||||
for j in range(101):
|
||||
theta = j / 100 * 360
|
||||
alpha = i * 360 + theta
|
||||
r = math.pow(math.e, 0.003 * alpha)
|
||||
data.append([r, theta])
|
||||
polar = Polar("极坐标系示例")
|
||||
polar.add("", data, symbol_size=0, symbol='circle', start_angle=-25, is_radiusaxis_show=False,
|
||||
area_color="#f3c5b3", area_opacity=0.5, is_angleaxis_show=False)
|
||||
polar.show_config()
|
||||
polar.render()
|
||||
```
|
||||

|
||||
@ -84,6 +84,7 @@ class Base(object):
|
||||
geo_normal_color=None,
|
||||
gravity=None,
|
||||
interval=None,
|
||||
is_angleaxis_show=None,
|
||||
is_area_show=None,
|
||||
is_axisline_show=None,
|
||||
is_calculable=None,
|
||||
@ -95,6 +96,7 @@ class Base(object):
|
||||
is_legend_show=None,
|
||||
is_liquid_animation=None,
|
||||
is_liquid_outline_show=None,
|
||||
is_radiusaxis_show=None,
|
||||
is_random=None,
|
||||
is_roam=None,
|
||||
is_rotatelabel=None,
|
||||
@ -112,6 +114,7 @@ class Base(object):
|
||||
layout=None,
|
||||
legend_orient=None,
|
||||
legend_pos=None,
|
||||
legend_top=None,
|
||||
line_curve=None,
|
||||
line_opacity=None,
|
||||
line_type=None,
|
||||
|
||||
@ -34,6 +34,8 @@ class Funnel(Base):
|
||||
_data.append({"name": _name, "value": _value})
|
||||
for a in attr:
|
||||
self._option.get('legend').get('data').append(a)
|
||||
_dset = set(self._option.get('legend').get('data'))
|
||||
self._option.get('legend').update(data=list(_dset))
|
||||
self._option.get('series').append({
|
||||
"type": "funnel",
|
||||
"name": name,
|
||||
|
||||
@ -64,6 +64,8 @@ class Pie(Base):
|
||||
rosetype = "radius"
|
||||
for a in attr:
|
||||
self._option.get('legend').get('data').append(a)
|
||||
_dset = set(self._option.get('legend').get('data'))
|
||||
self._option.get('legend').update(data=list(_dset))
|
||||
self._option.get('series').append({
|
||||
"type": "pie",
|
||||
"name": name,
|
||||
|
||||
@ -26,6 +26,8 @@ class Polar(Base):
|
||||
clockwise=True,
|
||||
is_stack=False,
|
||||
axis_range=None,
|
||||
is_angleaxis_show=True,
|
||||
is_radiusaxis_show=True,
|
||||
**kwargs):
|
||||
"""
|
||||
|
||||
@ -56,6 +58,10 @@ class Polar(Base):
|
||||
数据堆叠,同个类目轴上系列配置相同的 stack 值可以堆叠放置
|
||||
:param axis_range:
|
||||
坐标轴刻度范围。
|
||||
:param is_angleaxis_show:
|
||||
是否显示极坐标系的角度轴,默认为 True
|
||||
:param is_radiusaxis_show:
|
||||
是否显示极坐标系的径向轴,默认为 True
|
||||
:param kwargs:
|
||||
"""
|
||||
chart = get_all_options(**kwargs)
|
||||
@ -67,6 +73,9 @@ class Polar(Base):
|
||||
if axis_range:
|
||||
if len(axis_range) == 2:
|
||||
_amin, _amax = axis_range
|
||||
_area_style = {"normal": chart['area_style']}
|
||||
if kwargs.get('area_color', None) is None:
|
||||
_area_style = None
|
||||
if type in ("scatter", "line"):
|
||||
self._option.get('series').append({
|
||||
"type": type,
|
||||
@ -76,6 +85,7 @@ class Polar(Base):
|
||||
"symbolSize": symbol_size,
|
||||
"data": data,
|
||||
"label": chart['label'],
|
||||
"areaStyle": _area_style
|
||||
})
|
||||
elif type == "effectScatter":
|
||||
self._option.get('series').append({
|
||||
@ -122,6 +132,7 @@ class Polar(Base):
|
||||
if type not in ("barAngle", "barRadius"):
|
||||
self._option.update(
|
||||
angleAxis={
|
||||
"show":is_angleaxis_show,
|
||||
"type": polar_type,
|
||||
"data": angle_data,
|
||||
"clockwise": clockwise,
|
||||
@ -133,6 +144,7 @@ class Polar(Base):
|
||||
)
|
||||
self._option.update(
|
||||
radiusAxis={
|
||||
"show": is_radiusaxis_show,
|
||||
"type": polar_type,
|
||||
"data": radius_data,
|
||||
"min": _amin,
|
||||
|
||||
@ -302,6 +302,7 @@ def legend(type=None,
|
||||
is_legend_show=True,
|
||||
legend_orient="horizontal",
|
||||
legend_pos="center",
|
||||
legend_top='top',
|
||||
**kwargs):
|
||||
""" 图例组件。
|
||||
图例组件展现了不同系列的标记(symbol),颜色和名字。可以通过点击图例控制哪些系列不显示。
|
||||
@ -312,7 +313,9 @@ def legend(type=None,
|
||||
:param legend_orient:
|
||||
图例列表的布局朝向,有'horizontal', 'vertical'可选
|
||||
:param legend_pos:
|
||||
图例位置,有'left', 'center', 'right'可选
|
||||
图例组件离容器左侧的距离,有'left', 'center', 'right'可选
|
||||
:param legend_pos:
|
||||
图例组件离容器上侧的距离,有'top', 'center', 'bottom'可选
|
||||
:param kwargs:
|
||||
:return:
|
||||
"""
|
||||
@ -323,6 +326,7 @@ def legend(type=None,
|
||||
"selectedMode":selected_mode,
|
||||
"show": is_legend_show,
|
||||
"left": legend_pos,
|
||||
"top": legend_top,
|
||||
"orient": legend_orient
|
||||
}
|
||||
return _legend
|
||||
|
||||
@ -49,4 +49,29 @@ def test_pie():
|
||||
pie.add("", attr, [random.randint(0, 100) for _ in range(6)], radius=[50, 55], center=[65, 50], is_random=True)
|
||||
pie.add("", attr, [random.randint(20, 100) for _ in range(6)], radius=[0, 45], center=[65, 50], rosetype='radius')
|
||||
pie.show_config()
|
||||
pie.render()
|
||||
|
||||
# Pie_5
|
||||
pie = Pie('各类电影中"好片"所占的比例', "数据来着豆瓣", title_pos='center')
|
||||
pie.add("", ["剧情", ""], [25, 75], center=[10, 30], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None, )
|
||||
pie.add("", ["奇幻", ""], [24, 76], center=[30, 30], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None, legend_pos='left')
|
||||
pie.add("", ["爱情", ""], [14, 86], center=[50, 30], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None)
|
||||
pie.add("", ["惊悚", ""], [11, 89], center=[70, 30], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None)
|
||||
pie.add("", ["冒险", ""], [27, 73], center=[90, 30], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None)
|
||||
pie.add("", ["动作", ""], [15, 85], center=[10, 70], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None)
|
||||
pie.add("", ["喜剧", ""], [54, 46], center=[30, 70], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None)
|
||||
pie.add("", ["科幻", ""], [26, 74], center=[50, 70], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None)
|
||||
pie.add("", ["悬疑", ""], [25, 75], center=[70, 70], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None)
|
||||
pie.add("", ["犯罪", ""], [28, 72], center=[90, 70], radius=[18, 24],
|
||||
label_pos='center', is_label_show=True, label_text_color=None, is_legend_show=True, legend_top="center")
|
||||
pie.show_config()
|
||||
pie.render()
|
||||
@ -69,4 +69,30 @@ def test_polar():
|
||||
polar = Polar("极坐标系示例", width=1200, height=600)
|
||||
polar.add("Flower", data, start_angle=0, symbol=None, axis_range=[0, None])
|
||||
polar.show_config()
|
||||
polar.render()
|
||||
polar.render()
|
||||
|
||||
# polar_7
|
||||
data = []
|
||||
for i in range(361):
|
||||
t = i / 180 * math.pi
|
||||
r = math.sin(2 * t) * math.cos(2 * t)
|
||||
data.append([r, i])
|
||||
polar = Polar("极坐标系示例", width=1200, height=600)
|
||||
polar.add("Color-Flower", data, start_angle=0, symbol=None, axis_range=[0, None],
|
||||
area_color="#f71f24", area_opacity=0.6)
|
||||
polar.show_config()
|
||||
polar.render()
|
||||
|
||||
# polar_8
|
||||
data = []
|
||||
for i in range(5):
|
||||
for j in range(101):
|
||||
theta = j / 100 * 360
|
||||
alpha = i * 360 + theta
|
||||
r = math.pow(math.e, 0.003 * alpha)
|
||||
data.append([r, theta])
|
||||
polar = Polar("极坐标系示例")
|
||||
polar.add("", data, symbol_size=0, symbol='circle', start_angle=-25, is_radiusaxis_show=False,
|
||||
area_color="#f3c5b3", area_opacity=0.5, is_angleaxis_show=False)
|
||||
polar.show_config()
|
||||
polar.render()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user