mirror of
https://github.com/pyecharts/pyecharts.git
synced 2025-12-08 20:59:23 +00:00
🤝 Merge remote-tracking branch 'chenjiandongx/master'
This commit is contained in:
commit
54676eeb48
28
README.md
28
README.md
@ -8,7 +8,7 @@ pyecharts is a library to generate charts using Echarts. It simply provides the
|
||||
[Echarts](https://github.com/ecomfe/echarts) is an open source library from Baidu for data visualization in javascript. It has awesome demo pages so I started to look out for an interface library so that I could use it in Python. I ended up with [echarts-python](https://github.com/yufeiminds/echarts-python) on github but it lacks of documentation and was not updated for a while. Just like many other Python projects, I started my own project, pyecharts, referencing echarts-python and another library [pygal](https://github.com/Kozea/pygal).
|
||||
|
||||
## Instatllation
|
||||
pyecharts works on Python2 and Python3. The latest release is 0.1.9.1. For more information please refer to [changelog.md](https://github.com/chenjiandongx/pyecharts/blob/master/changelog.md)
|
||||
pyecharts works on Python2 and Python3. The latest release is 0.1.9.2. For more information please refer to [changelog.md](https://github.com/chenjiandongx/pyecharts/blob/master/changelog.md)
|
||||
|
||||
You can install it via pip
|
||||
```
|
||||
@ -38,7 +38,31 @@ bar.render()
|
||||
|
||||
It will creat a file named render.html in the root directory, open file with your borwser.
|
||||
|
||||

|
||||

|
||||
|
||||
## Working with pandas & numpy
|
||||
```python
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
from pyecharts import Bar
|
||||
|
||||
index = pd.date_range('3/8/2017', periods=6, freq='M')
|
||||
df1 = pd.DataFrame(np.random.randn(6), index=index)
|
||||
dtvalue1, pdattr1 = Bar.pdcast(df1)
|
||||
|
||||
df2 = pd.DataFrame(np.random.randn(6), index=index)
|
||||
dtvalue2, pdattr2 = Bar.pdcast(df2)
|
||||
|
||||
dtvalue1 = [i[0] for i in dtvalue1]
|
||||
dtvalue2 = [i[0] for i in dtvalue2]
|
||||
|
||||
bar = Bar('Bar chart', 'Profit and loss situation')
|
||||
bar.add('profit', pdattr1, dtvalue1)
|
||||
bar.add('loss', pdattr2, dtvalue2)
|
||||
bar.render()
|
||||
```
|
||||

|
||||
|
||||
## Documentation
|
||||
* [中文档案](https://github.com/chenjiandongx/pyecharts/blob/master/document/doc_zh_CN.md)
|
||||
|
||||
19
changelog.md
19
changelog.md
@ -5,10 +5,10 @@
|
||||
第一个稳定版本
|
||||
|
||||
* version 0.1.5
|
||||
增加了 K 线图
|
||||
新增了 K 线图
|
||||
|
||||
* version 0.1.6
|
||||
增加了热力图
|
||||
新增了热力图
|
||||
|
||||
* version 0.1.7
|
||||
增加并行显示图表功能
|
||||
@ -20,14 +20,21 @@
|
||||
* version 0.1.9
|
||||
* 解决在 macos 下安装出错的问题。感谢 [@chfw](https://github.com/chfw) 提供的解决方案。
|
||||
* datazoom 中增加了将组件效果显示在 y 坐标轴中的功能。(参见 KLine 图)
|
||||
* 增加了对 Pandas 和 Numpy 数据的简单处理。解决直接传入 Pandas 和 Numpy 数据类型出错的问题。(参见开始使用)
|
||||
* 增加 Bar3D, Line3D, Scatter3D 三种 3D 立体图表。
|
||||
* 新增对 Pandas 和 Numpy 数据的简单处理。解决直接传入 Pandas 和 Numpy 数据类型出错的问题。(参见开始使用)
|
||||
* 新增 Bar3D, Line3D, Scatter3D 三种 3D 立体图表。
|
||||
|
||||
* version 0.1.9.1(当前版本)
|
||||
* version 0.1.9.1
|
||||
* 加入 Travis-CI 自动化测试。感谢 [@chfw](https://github.com/chfw) 提供的代码。
|
||||
* legend 增加 legend_selectedmode 参数,图例可以设置为单例或者多例。(参见 Radar 图)
|
||||
* visualmap 组件增加 visual_map 和 visual_range_size 参数。现在支持映射到颜色和图形大小两种方式。(参见 Scatter 图)
|
||||
|
||||
* version 0.1.9.2(当前版本)
|
||||
* 新增 xaxis_rotate, yaxis_rotate 参数,可通过设置该参数解决强制显示所有坐标轴标签时因过于密集重叠的问题。参见(Bar 图)
|
||||
* 新增 xaxis_min, xaxis_max. yaxis_min, yaxis_max 参数,可设置坐标轴上的最大最小值,针对数值轴有效。
|
||||
* 解决 3D 图形不能在 jupyter notebook 上正常显示的问题。
|
||||
* render() 方法现在为离线模式,实现本地生成 .html 文件,加载速度更快。
|
||||
* 废弃 render_notebook() 方法,现可直接调用图形实例显示在 jupyter notebook 上。
|
||||
|
||||
## 项目期待
|
||||
|
||||
* 视项目情况考虑增加一份英文文档
|
||||
* 更好地集成到 Django + Flask 中。
|
||||
@ -90,22 +90,77 @@ cast(seq)
|
||||
3. Dictionaries
|
||||
{A1: B1, A2: B2, A3: B3, A4: B4} -- > k_lst[ A[i1, i2...] ], v_lst[ B[i1, i2...] ]
|
||||
|
||||
如果使用的是 Numpy 或者 Pandas,直接将数据放入 ```add()``` 方法也可能会出现问题,因为 ```add()``` 方法接受的是两个 list 列表。最后所有的配置项都是要经过 JSON 序列化的,像 int64 这种类型的数据在这个过程是会报错的。
|
||||
it provides ```pdcast(pddata)``` and ``` npcast(npdata)``` methods to handle numpy & pandas data。
|
||||
|
||||
pdcast(),It accepts Series or DataFrame types.
|
||||
```python
|
||||
@staticmethod
|
||||
pdcast(pddata)
|
||||
``` handle Series and DataFrame type in pandas, return value_lst and index_list ```
|
||||
```
|
||||
传入的类型为 Series、DataFrame 的话,pdcast() 会返回两个确保类型正确的列表(整个列表的数据类型为 float 或者 str,会先尝试转换为数值类型的 float,出现异常再尝试转换为 str 类型),value_lst 和 index_lst,分别为 Series.values/DataFrame.values 和 Series.index/DataFrame.index 列表。再将得到的数据传入 ```add()``` 方法即可(DataFrame 多个维度时返回一个嵌套列表。比较适合像 Radar, Parallel, HeatMap 这些需要传入嵌套列表([[ ], [ ]])数据的图表。)
|
||||
|
||||
Series type
|
||||
```python
|
||||
from pyecharts import Bar
|
||||
import pandas as pd
|
||||
|
||||
pddata = pd.Series([1, 2, 3, 4], index=[1, 'b', 'c', 'd'])
|
||||
vlst, ilst = Bar.pdcast(pddata)
|
||||
|
||||
print(vlst)
|
||||
>>> [1.0, 2.0, 3.0, 4.0]
|
||||
print(ilst)
|
||||
>>> ['1', 'b', 'c', 'd']
|
||||
```
|
||||
|
||||
DataFrame type
|
||||
```python
|
||||
from pyecharts import Bar
|
||||
import pandas as pd
|
||||
|
||||
pddt = pd.DataFrame([[1, 2, 3, 4], [2, 3, 4, 5], [4.1, 5.2, 6.3, 7.4]], index=["A", "B", "C"])
|
||||
vlst, ilst = Bar.pdcast(pddata)
|
||||
|
||||
print(vlst)
|
||||
>>> [[1.0, 2.0, 3.0, 4.0], [2.0, 3.0, 4.0, 5.0], [4.1, 5.2, 6.3, 7.4]]
|
||||
print(ilst)
|
||||
>>> ['A', 'B', 'C']
|
||||
```
|
||||
|
||||
npcast(),It accepts numpy.array type.
|
||||
```python
|
||||
@staticmethod
|
||||
npcast(npdata)
|
||||
``` handle the ndarray type in Numpy, return a list that ensures the correct type. Returns the nested list if there are multiple dimensions.```
|
||||
```
|
||||
|
||||
Numpy.array type
|
||||
```python
|
||||
from pyecharts import Bar
|
||||
import numpy ad np
|
||||
|
||||
npdata = np.array([[1, 2, 3, 4], [2, 4, 5.0, 6.3]])
|
||||
print(npdata)
|
||||
>>> [[1.0, 2.0, 3.0, 4.0], [2.0, 4.0, 5.0, 6.3]]
|
||||
```
|
||||
|
||||
**Of course you can use the cooler way,use Jupyter Notebook to show the chart.But what matplotlib have,so do pyecharts**
|
||||
|
||||
like this
|
||||
|
||||

|
||||

|
||||
|
||||
and this
|
||||
|
||||

|
||||

|
||||
|
||||

|
||||
more Jupyter notebook examples, please refer to [notebook-use-cases](https://github.com/chenjiandongx/pyecharts/blob/master/document/notebook-use-cases.ipynb)。you could download and run it on your notebook.
|
||||
|
||||
**Tip:** The function was official added in 0.1.9.1 version,please update the newest version to use it.
|
||||
**Tip:** The function was official added in 0.1.9.2 version,please update the newest version to use it.
|
||||
|
||||
They are just some examples.If you want use Jupyter Notebook to show your chart,just call ```render_notebook()``` ,compatible with Python2 and Python3's Jupyter Notebook environment at sametime.All the chart can display normaly,the same interaction experience to browser,there's no need to make a complex powerpoint!!
|
||||
> Special thanks to [@ygw365](https://github.com/ygw365) for provide code templates and special thanks to [muxuezi](https://github.com/muxuezi) for help of improving the code.Special thanks!And welcome developers to join us.We make the program improved and perfetcted together!
|
||||
If you want use Jupyter Notebook to show your chart,just call Chart instance,compatible with Python2 and Python3's Jupyter Notebook environment at sametime.All the chart can display normaly,the same interaction experience to browser,there's no need to make a complex powerpoint!!
|
||||
|
||||
The parameter a chart type initialize accept(the same to all the chart type).
|
||||
|
||||
@ -169,6 +224,12 @@ xyAxis:x, y axis in cartesian coordinate system(Line、Bar、Scatter、EffectS
|
||||
Name of xAxis
|
||||
* xaxis_name_pos -> str
|
||||
Location of xAxis name.It can be 'start','middle','end'
|
||||
* xaxis_rotate -> int
|
||||
Rotation degree of xaxis label, which is especially useful when there is no enough space for category axis.Rotation degree is from -90 to 90.
|
||||
* xaxis_min -> int/float
|
||||
The minimun value of xaxis.
|
||||
* xaxis_max -> int/float
|
||||
The maximun value of xaxis.
|
||||
* y_axis -> list
|
||||
yAxis data
|
||||
* yaxis_formatter -> str
|
||||
@ -177,9 +238,14 @@ xyAxis:x, y axis in cartesian coordinate system(Line、Bar、Scatter、EffectS
|
||||
Name of yAxis
|
||||
* yaxis_name_pos -> str
|
||||
Location of yAxis name.It can be 'start','middle','end'
|
||||
* yaxis_rotate -> int
|
||||
Rotation degree of xaxis label, which is especially useful when there is no enough space for category axis.Rotation degree is from -90 to 90.
|
||||
* yaxis_min -> int/float
|
||||
The minimun value of yaxis.
|
||||
* yaxis_max -> int/float
|
||||
The maximun value of yaxis.
|
||||
* interval -> int
|
||||
The display interval of the axis scale label is valid in the category axis.
|
||||
By default, labels are displayed using labels that do not overlap the labels.
|
||||
The display interval of the axis scale label is valid in the category axis.By default, labels are displayed using labels that do not overlap the labels.
|
||||
Set to 0 to force all labels to be displayed and label is one by one if setting as 1; If 2, it will be one label separates from each other, and so on.
|
||||
|
||||
|
||||
@ -429,6 +495,77 @@ add(name, x_axis, y_axis, data, grid3D_opacity=1, grid3D_shading='color', **kwar
|
||||
* 'lambert': Through the classic lambert coloring to show the light and shade.
|
||||
* 'realistic': Realistic rendering.
|
||||
|
||||
```python
|
||||
from pyecharts import Bar3D
|
||||
|
||||
bar3d = Bar3D("3D 柱状图示例", width=1200, height=600)
|
||||
x_axis = ["12a", "1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a",
|
||||
"12p", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p", "10p", "11p"]
|
||||
y_aixs = ["Saturday", "Friday", "Thursday", "Wednesday", "Tuesday", "Monday", "Sunday"]
|
||||
data = [[0, 0, 5], [0, 1, 1], [0, 2, 0], [0, 3, 0], [0, 4, 0], [0, 5, 0], [0, 6, 0], [0, 7, 0],
|
||||
[0, 8, 0],[0, 9, 0], [0, 10, 0], [0, 11, 2], [0, 12, 4], [0, 13, 1], [0, 14, 1], [0, 15, 3],
|
||||
[0, 16, 4], [0, 17, 6], [0, 18, 4], [0, 19, 4], [0, 20, 3], [0, 21, 3], [0, 22, 2], [0, 23, 5],
|
||||
[1, 0, 7], [1, 1, 0], [1, 2, 0], [1, 3, 0], [1, 4, 0], [1, 5, 0], [1, 6, 0], [1, 7, 0], [1, 8, 0],
|
||||
[1, 9, 0], [1, 10, 5], [1, 11, 2], [1, 12, 2], [1, 13, 6], [1, 14, 9], [1, 15, 11], [1, 16, 6], [1, 17, 7],
|
||||
[1, 18, 8], [1, 19, 12], [1, 20, 5], [1, 21, 5], [1, 22, 7], [1, 23, 2], [2, 0, 1], [2, 1, 1],
|
||||
[2, 2, 0], [2, 3, 0], [2, 4, 0], [2, 5, 0], [2, 6, 0], [2, 7, 0], [2, 8, 0], [2, 9, 0], [2, 10, 3],
|
||||
[2, 11, 2], [2, 12, 1], [2, 13, 9], [2, 14, 8], [2, 15, 10], [2, 16, 6], [2, 17, 5], [2, 18, 5],
|
||||
[2, 19, 5], [2, 20, 7], [2, 21, 4], [2, 22, 2], [2, 23, 4], [3, 0, 7], [3, 1, 3], [3, 2, 0], [3, 3, 0],
|
||||
[3, 4, 0], [3, 5, 0], [3, 6, 0], [3, 7, 0], [3, 8, 1], [3, 9, 0], [3, 10, 5], [3, 11, 4], [3, 12, 7],
|
||||
[3, 13, 14], [3, 14, 13], [3, 15, 12], [3, 16, 9], [3, 17, 5], [3, 18, 5], [3, 19, 10], [3, 20, 6],
|
||||
[3, 21, 4], [3, 22, 4], [3, 23, 1], [4, 0, 1], [4, 1, 3], [4, 2, 0], [4, 3, 0], [4, 4, 0], [4, 5, 1],
|
||||
[4, 6, 0], [4, 7, 0], [4, 8, 0], [4, 9, 2], [4, 10, 4], [4, 11, 4], [4, 12, 2], [4, 13, 4], [4, 14, 4],
|
||||
[4, 15, 14], [4, 16, 12], [4, 17, 1], [4, 18, 8], [4, 19, 5], [4, 20, 3], [4, 21, 7], [4, 22, 3],
|
||||
[4, 23, 0], [5, 0, 2], [5, 1, 1], [5, 2, 0], [5, 3, 3], [5, 4, 0], [5, 5, 0], [5, 6, 0], [5, 7, 0],
|
||||
[5, 8, 2], [5, 9, 0], [5, 10, 4], [5, 11, 1], [5, 12, 5], [5, 13, 10], [5, 14, 5], [5, 15, 7], [5, 16, 11],
|
||||
[5, 17, 6], [5, 18, 0], [5, 19, 5], [5, 20, 3], [5, 21, 4], [5, 22, 2], [5, 23, 0], [6, 0, 1], [6, 1, 0],
|
||||
[6, 2, 0], [6, 3, 0], [6, 4, 0], [6, 5, 0], [6, 6, 0], [6, 7, 0], [6, 8, 0], [6, 9, 0], [6, 10, 1],
|
||||
[6, 11, 0], [6, 12, 2], [6, 13, 1], [6, 14, 3], [6, 15, 4], [6, 16, 0], [6, 17, 0], [6, 18, 0], [6, 19, 0],
|
||||
[6, 20, 1], [6, 21, 2], [6, 22, 2], [6, 23, 6]]
|
||||
range_color = ['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf',
|
||||
'#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026']
|
||||
bar3d.add("", x_axis, y_aixs, [[d[1], d[0], d[2]] for d in data], is_visualmap=True,
|
||||
visual_range=[0, 20], visual_range_color=range_color, grid3D_width=200, grid3D_depth=80)
|
||||
bar3d.show_config()
|
||||
bar3d.render()
|
||||
```
|
||||

|
||||
|
||||
``` grid3D_shading``` could make bar look more real
|
||||
```python
|
||||
bar3d = Bar3D("3D 柱状图示例", width=1200, height=600)
|
||||
bar3d.add("", x_axis, y_aixs, [[d[1], d[0], d[2]] for d in data], is_visualmap=True,
|
||||
visual_range=[0, 20], visual_range_color=range_color, grid3D_width=200, grid3D_depth=80,
|
||||
grid3D_shading='lambert')
|
||||
bar3d.show_config()
|
||||
bar3d.render()
|
||||
```
|
||||

|
||||
|
||||
```is_grid3D_rotate``` could let it rotate automatically
|
||||
```python
|
||||
bar3d = Bar3D("3D 柱状图示例", width=1200, height=600)
|
||||
bar3d.add("", x_axis, y_aixs, [[d[1], d[0], d[2]] for d in data], is_visualmap=True,
|
||||
visual_range=[0, 20], visual_range_color=range_color, grid3D_width=200, grid3D_depth=80,
|
||||
is_grid3D_rotate=True)
|
||||
bar3d.show_config()
|
||||
bar3d.render()
|
||||
```
|
||||

|
||||
|
||||
set ``` grid3D_rotate_speed``` to adjust the rotation speed
|
||||
```python
|
||||
bar3d = Bar3D("3D 柱状图示例", width=1200, height=600)
|
||||
bar3d.add("", x_axis, y_aixs, [[d[1], d[0], d[2]] for d in data], is_visualmap=True,
|
||||
visual_range=[0, 20], visual_range_color=range_color, grid3D_width=200, grid3D_depth=80,
|
||||
is_grid3D_rotate=True, grid3D_rotate_speed=180)
|
||||
bar3d.show_config()
|
||||
bar3d.render()
|
||||
```
|
||||

|
||||
|
||||
**Tip:** more details aboutt gird3D,please refer to [Global-options](https://github.com/chenjiandongx/pyecharts/blob/master/document/doc_en_US.md#Global-options)
|
||||
|
||||
|
||||
## EffectScatter
|
||||
> The scatter graph with ripple animation. The special animation effect can visually highlights some data.
|
||||
@ -983,8 +1120,61 @@ line.render()
|
||||
|
||||
|
||||
# Line3D
|
||||
Line3D.add() signatures
|
||||
```python
|
||||
add(name, data, grid3D_opacity=1, **kwargs)
|
||||
```
|
||||
* name -> str
|
||||
Series name used for displaying in tooltip and filtering with legend,or updaing data and configuration with setOption.
|
||||
* data -> [[], []]
|
||||
data of line3D
|
||||
* grid3D_opacity -> float
|
||||
default -> 1
|
||||
opacity of gird3D item
|
||||
|
||||
draw a spring
|
||||
```python
|
||||
from pyecharts import Line3D
|
||||
|
||||
import math
|
||||
_data = []
|
||||
for t in range(0, 25000):
|
||||
_t = t / 1000
|
||||
x = (1 + 0.25 * math.cos(75 * _t)) * math.cos(_t)
|
||||
y = (1 + 0.25 * math.cos(75 * _t)) * math.sin(_t)
|
||||
z = _t + 2.0 * math.sin(75 * _t)
|
||||
_data.append([x, y, z])
|
||||
range_color = ['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf',
|
||||
'#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026']
|
||||
line3d = Line3D("3D 折线图示例", width=1200, height=600)
|
||||
line3d.add("", _data, is_visualmap=True, visual_range_color=range_color, visual_range=[0, 30],
|
||||
grid3D_rotate_sensitivity=5)
|
||||
line3d.render()
|
||||
```
|
||||

|
||||
|
||||
rotating spring
|
||||
```python
|
||||
from pyecharts import Line3D
|
||||
|
||||
import math
|
||||
_data = []
|
||||
for t in range(0, 25000):
|
||||
_t = t / 1000
|
||||
x = (1 + 0.25 * math.cos(75 * _t)) * math.cos(_t)
|
||||
y = (1 + 0.25 * math.cos(75 * _t)) * math.sin(_t)
|
||||
z = _t + 2.0 * math.sin(75 * _t)
|
||||
_data.append([x, y, z])
|
||||
range_color = ['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf',
|
||||
'#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026']
|
||||
line3d = Line3D("3D 折线图示例", width=1200, height=600)
|
||||
line3d.add("", _data, is_visualmap=True, visual_range_color=range_color, visual_range=[0, 30],
|
||||
is_grid3D_rotate=True, grid3D_rotate_speed=180)
|
||||
line3d.render()
|
||||
```
|
||||

|
||||
|
||||
**Tip:** more details aboutt gird3D,please refer to [Global-options](https://github.com/chenjiandongx/pyecharts/blob/master/document/doc_en_US.md#Global-options)
|
||||
|
||||
## Liquid
|
||||
> Liquid chart is usually used to represent data in percentage.
|
||||
@ -1584,7 +1774,32 @@ scatter.render()
|
||||
|
||||
|
||||
# Scatter3D
|
||||
Scatter3D.add() signatures
|
||||
```python
|
||||
add(name, data, grid3D_opacity=1, **kwargs)
|
||||
```
|
||||
* name -> str
|
||||
Series name used for displaying in tooltip and filtering with legend,or updaing data and configuration with setOption.
|
||||
* data -> [[], []]
|
||||
data of line3D
|
||||
* grid3D_opacity -> float
|
||||
default -> 1
|
||||
opacity of gird3D item
|
||||
|
||||
```python
|
||||
from pyecharts import Scatter3D
|
||||
|
||||
import random
|
||||
data = [[random.randint(0, 100), random.randint(0, 100), random.randint(0, 100)] for _ in range(80)]
|
||||
range_color = ['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf',
|
||||
'#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026']
|
||||
scatter3D = Scatter3D("3D 散点图示例", width=1200, height=600)
|
||||
scatter3D.add("", data, is_visualmap=True, visual_range_color=range_color)
|
||||
scatter3D.render()
|
||||
```
|
||||

|
||||
|
||||
**Tip:** more details aboutt gird3D,please refer to [Global-options](https://github.com/chenjiandongx/pyecharts/blob/master/document/doc_en_US.md#Global-options)
|
||||
|
||||
## WordCloud
|
||||
WordCloud.add() signatures
|
||||
|
||||
@ -1,16 +1,5 @@
|
||||
# 关于作者想说的
|
||||
作为 pyecharts 的作者,很高兴看到 pyecharts 最近这么受欢迎,一度冲上了 Python daily trending 和 weekly trending 前三名。大家对这个项目的反馈也都不错,在这里我真诚的感谢大家对这个项目的支持。
|
||||
随着使用项目的人越来越多,已经收到了不少希望推出一份英文文档的请求,但是大家提新需求的速度已经远远快于我的开发速度......我还要测试以及解决提出的 issue,实在是没什么时间(加上我英语水平不高这点我是不会告诉你的)。
|
||||
### 所以,划重点!!!
|
||||
在这里,我诚恳地向各位对这个项目感兴趣,想参与到项目中来的开发者发出邀请,希望你们可以参与到英文文档的编写中来,成为这个项目的贡献者,一起推动这个项目的发展。英文文档在这里 [doc_en_US.md](https://github.com/chenjiandongx/pyecharts/blob/master/document/doc_en_US.md) ,我已经写了一些,但是还差挺多的。别犹豫了,来吧!
|
||||
### 接着,划重点!!!
|
||||
想参与到英文文档开发中来的开发者,请联系我邮箱,chenjiandongx@qq.com,或者加入下面这个微信群,我们可以来具体讨论。不然直接 fork 一份,编写后提交 PR 也行,我看到了会及时 merge 的。
|
||||
|
||||

|
||||
### 最后,划重点!!!
|
||||
接下来我就暂时不更新版本了,因为作者要出去玩耍几天了,不然感觉这样下去的话我这个暑假就没了!
|
||||
|
||||
# pyecharts 文档
|
||||
|
||||
pyecharts 是一个用于生成 Echarts 图表的类库。实际上就是 Echarts 与 Python 的对接。
|
||||
|
||||
[](https://travis-ci.org/chenjiandongx/pyecharts)
|
||||
@ -112,8 +101,35 @@ pdcast(),接受的参数可以为 Series 或者 DataFrame 类型。
|
||||
pdcast(pddata)
|
||||
``` 用于处理 Pandas 中的 Series 和 DataFrame 类型,返回 value_lst, index_list 两个列表 ```
|
||||
```
|
||||
1. 传入的类型为 Series 的话,pdcast() 会返回两个确保类型正确的列表(整个列表的数据类型为 float 或者 str,会先尝试转换为数值类型的 float,出现异常再尝试转换为 str 类型),value_lst 和 index_lst,分别为 Series.values 和 Series.index 列表。
|
||||
2. 传入的类型为 DataFrame 的话,pdcast() 会返回一个确保类型正确的列表(整个列表的数据类型为 float 或者 str,会先尝试转换为数值类型的 float,出现异常再尝试转换为 str 类型),为 DataFrame.values 列表。多个维度时返回一个嵌套列表。比较适合像 Radar, Parallel, HeatMap 这些需要传入嵌套列表([[ ], [ ]])数据的图表。
|
||||
传入的类型为 Series、DataFrame 的话,pdcast() 会返回两个确保类型正确的列表(整个列表的数据类型为 float 或者 str,会先尝试转换为数值类型的 float,出现异常再尝试转换为 str 类型),value_lst 和 index_lst,分别为 Series.values/DataFrame.values 和 Series.index/DataFrame.index 列表。再将得到的数据传入 ```add()``` 方法即可(DataFrame 多个维度时返回一个嵌套列表。比较适合像 Radar, Parallel, HeatMap 这些需要传入嵌套列表([[ ], [ ]])数据的图表。)
|
||||
|
||||
Series 类型
|
||||
```python
|
||||
from pyecharts import Bar
|
||||
import pandas as pd
|
||||
|
||||
pddata = pd.Series([1, 2, 3, 4], index=[1, 'b', 'c', 'd'])
|
||||
vlst, ilst = Bar.pdcast(pddata)
|
||||
|
||||
print(vlst)
|
||||
>>> [1.0, 2.0, 3.0, 4.0]
|
||||
print(ilst)
|
||||
>>> ['1', 'b', 'c', 'd']
|
||||
```
|
||||
|
||||
DataFrame 类型
|
||||
```python
|
||||
from pyecharts import Bar
|
||||
import pandas as pd
|
||||
|
||||
pddt = pd.DataFrame([[1, 2, 3, 4], [2, 3, 4, 5], [4.1, 5.2, 6.3, 7.4]], index=["A", "B", "C"])
|
||||
vlst, ilst = Bar.pdcast(pddata)
|
||||
|
||||
print(vlst)
|
||||
>>> [[1.0, 2.0, 3.0, 4.0], [2.0, 3.0, 4.0, 5.0], [4.1, 5.2, 6.3, 7.4]]
|
||||
print(ilst)
|
||||
>>> ['A', 'B', 'C']
|
||||
```
|
||||
|
||||
npcast(),接受的参数为 Numpy.array 类型。
|
||||
```python
|
||||
@ -122,21 +138,30 @@ npcast(npdata)
|
||||
``` 用于处理 Numpy 中的 ndarray 类型,返回一个确保类型正确的列表。如果多个维度的话返回嵌套列表。```
|
||||
```
|
||||
|
||||
Numpy.array 类型
|
||||
```python
|
||||
from pyecharts import Bar
|
||||
import numpy ad np
|
||||
|
||||
npdata = np.array([[1, 2, 3, 4], [2, 4, 5.0, 6.3]])
|
||||
print(npdata)
|
||||
>>> [[1.0, 2.0, 3.0, 4.0], [2.0, 4.0, 5.0, 6.3]]
|
||||
```
|
||||
|
||||
**当然你也可以采用更加酷炫的方式,使用 Jupyter Notebook 来展示图表,matplotlib 有的,pyecharts 也会有的**
|
||||
|
||||
比如这样
|
||||
|
||||

|
||||

|
||||
|
||||
还有这样
|
||||
|
||||

|
||||

|
||||
|
||||

|
||||
更多 Jupyter notebook 的例子请参考 [notebook-use-cases](https://github.com/chenjiandongx/pyecharts/blob/master/document/notebook-use-cases.ipynb)。可下载后运行看看。
|
||||
|
||||
|
||||
这里只是举几个例子。如需使用 Jupyter Notebook 来展示图表,只需要调用 ```render_notebook()``` 即可,同时兼容 Python2 和 Python3 的 Jupyter Notebook 环境。所有图表均可正常显示(除了 3D 图),与浏览器一致的交互体验,这下展示报告连 PPT 都省了!!
|
||||
> 在这里要特别感谢 [@ygw365](https://github.com/ygw365) 提供这部分的代码模板 和 [@muxuezi](https://github.com/muxuezi) 协助对代码进行改进,特此感谢!
|
||||
如需使用 Jupyter Notebook 来展示图表,只需要调用自身实例即可,同时兼容 Python2 和 Python3 的 Jupyter Notebook 环境。所有图表均可正常显示,与浏览器一致的交互体验,这下展示报告连 PPT 都省了!!
|
||||
**Tip:** 从 0.1.9.2 版本开始,不再使用 ```render_notebook()``` 方法,现已采用更加 pythonic 的做法。直接调用本身实例就可以了。
|
||||
|
||||
图表类初始化所接受的参数(所有类型的图表都一样)。
|
||||
|
||||
@ -184,6 +209,10 @@ xyAxis:直角坐标系中的 x、y 轴(Line、Bar、Scatter、EffectScatter、
|
||||
x 轴名称位置,有'start','middle','end'可选
|
||||
* xaxis_rotate -> int
|
||||
刻度标签旋转的角度,在类目轴的类目标签显示不下的时候可以通过旋转防止标签之间重叠。默认为 0,即不旋转。旋转的角度从 -90 度到 90 度。
|
||||
* xaxis_min -> int/float
|
||||
x 坐标轴刻度最小值,默认为自适应。
|
||||
* xaxis_max -> int/float
|
||||
x 坐标轴刻度最大值,默认为自适应。
|
||||
* y_axis -> list
|
||||
y 坐标轴数据
|
||||
* yaxis_formatter -> str
|
||||
@ -192,6 +221,10 @@ xyAxis:直角坐标系中的 x、y 轴(Line、Bar、Scatter、EffectScatter、
|
||||
y 轴名称
|
||||
* yaxis_name_pos -> str
|
||||
y 轴名称位置,有'start', 'middle','end'可选
|
||||
* yaxis_min -> int/float
|
||||
y 坐标轴刻度最小值,默认为自适应。
|
||||
* yaxis_max -> int/float
|
||||
y 坐标轴刻度最大值,默认为自适应。
|
||||
* yaxis_rotate -> int
|
||||
刻度标签旋转的角度,在类目轴的类目标签显示不下的时候可以通过旋转防止标签之间重叠。默认为 0,即不旋转。旋转的角度从 -90 度到 90 度。
|
||||
* interval -> int
|
||||
@ -391,7 +424,20 @@ bar.render()
|
||||

|
||||
|
||||
**Tip:** datazoom 适合所有平面直角坐标系图形,也就是(Line、Bar、Scatter、EffectScatter、Kline)
|
||||
**Tip:** 可以通过 label_color 来设置柱状的颜色,如 ['#eee', '#000'],所有的图表类型的图例颜色都可通过 label_color 来修改。
|
||||
|
||||
当 x 轴或者 y 轴的标签因为过于密集而导致全部显示出来会重叠的话,可采用使标签旋转的方法。
|
||||
```python
|
||||
attr = ["{}天".format(i) for i in range(20)]
|
||||
v1 = [random.randint(1, 20) for _ in range(20)]
|
||||
bar = Bar("坐标轴标签旋转示例")
|
||||
bar.add("", attr, v1, interval=0, xaxis_rotate=30, yaxis_rotate=30)
|
||||
bar.show_config()
|
||||
bar.render()
|
||||
```
|
||||

|
||||
|
||||
**Tip:** 可通过设置 xaxis_min/xaxis_max/yaxis_min/yaxis_max 来调整 x 轴和 y 轴上的最大最小值。针对数值轴有效!
|
||||
**Tip:** 可以通过 label_color 来设置柱状的颜色,如 ['#eee', '#000'],所有的图表类型的图例颜色都可通过 label_color 来修改。
|
||||
|
||||
|
||||
## Bar3D(3D 柱状图)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
#coding=utf-8
|
||||
|
||||
__version__ = '0.1.9.1'
|
||||
__version__ = '0.1.9.2'
|
||||
__author__ = 'chenjiandongx'
|
||||
|
||||
from pyecharts.charts.bar import Bar
|
||||
|
||||
@ -214,9 +214,13 @@ class Base(object):
|
||||
xaxis_name_pos=None,
|
||||
xaxis_name=None,
|
||||
xaxis_rotate=None,
|
||||
xaxis_min=None,
|
||||
xaxis_max=None,
|
||||
xy_text_size=None,
|
||||
yaxis_formatter=None,
|
||||
yaxis_rotate=None,
|
||||
yaxis_min=None,
|
||||
yaxis_max=None,
|
||||
yaxis_name_pos=None,
|
||||
yaxis_name=None):
|
||||
""" The base class's add() is just to provide a hint option """
|
||||
@ -381,7 +385,6 @@ class Base(object):
|
||||
_dtvalue = pddata.values.astype(float).tolist()
|
||||
except:
|
||||
_dtvalue = pddata.values.astype(str).tolist()
|
||||
return _dtvalue
|
||||
try:
|
||||
_pdattr = pddata.index.astype(float).tolist()
|
||||
except:
|
||||
@ -440,7 +443,7 @@ class Base(object):
|
||||
if s.get('type') == "liquidFill":
|
||||
temple = "lq.html"
|
||||
break
|
||||
my_option = json.dumps(self._option, indent=4, ensure_ascii=False)
|
||||
my_option = json.dumps(self._option, indent=4)
|
||||
tmp = self._jinja2_env.get_template(temple)
|
||||
html = tmp.render(myOption=my_option,
|
||||
chart_id=uuid.uuid4().hex,
|
||||
@ -493,9 +496,8 @@ class Base(object):
|
||||
|
||||
:return:
|
||||
"""
|
||||
warnings.warn(
|
||||
"This function is deprecated since 0.1.9.1" +
|
||||
" Simply passing the chart instance is enough")
|
||||
warnings.warn("\n" + "This function is deprecated since 0.1.9.1" +
|
||||
" Simply passing the chart instance is enough")
|
||||
from IPython.display import HTML
|
||||
return HTML(self._repr_html_())
|
||||
|
||||
|
||||
@ -194,10 +194,14 @@ def xy_axis(type=None,
|
||||
xaxis_name="",
|
||||
xaxis_name_pos="middle",
|
||||
xaxis_rotate=0,
|
||||
xaxis_min=None,
|
||||
xaxis_max=None,
|
||||
interval="auto",
|
||||
yaxis_name="",
|
||||
yaxis_name_pos="middle",
|
||||
yaxis_rotate=0,
|
||||
yaxis_min=None,
|
||||
yaxis_max=None,
|
||||
is_convert=False,
|
||||
x_axis=None,
|
||||
yaxis_formatter="",
|
||||
@ -217,6 +221,10 @@ def xy_axis(type=None,
|
||||
:param xaxis_rotate:
|
||||
Rotation degree of xaxis label, which is especially useful when there is no enough space for category axis.
|
||||
Rotation degree is from -90 to 90.
|
||||
:param xaxis_min:
|
||||
The minimun value of xaxis.
|
||||
:param xaxis_max:
|
||||
The maximun value of xaxis.
|
||||
:param interval:
|
||||
The display interval of the axis scale label is valid in the category axis.
|
||||
By default, labels are displayed using labels that do not overlap the labels
|
||||
@ -229,6 +237,10 @@ def xy_axis(type=None,
|
||||
:param yaxis_rotate:
|
||||
Rotation degree of yaxis label, which is especially useful when there is no enough space for category axis.
|
||||
Rotation degree is from -90 to 90.
|
||||
:param yaxis_min:
|
||||
The minimun value of yaxis.
|
||||
:param yaxis_max:
|
||||
The maximun value of yaxis.
|
||||
:param is_convert:
|
||||
It specifies whether to convert xAxis and yAxis.
|
||||
:param x_axis:
|
||||
@ -248,6 +260,8 @@ def xy_axis(type=None,
|
||||
"interval": interval,
|
||||
"rotate": xaxis_rotate,
|
||||
},
|
||||
"min": xaxis_min,
|
||||
"max": xaxis_max
|
||||
}
|
||||
_yAxis = {
|
||||
"name": yaxis_name,
|
||||
@ -257,7 +271,9 @@ def xy_axis(type=None,
|
||||
"axisLabel": {
|
||||
"formatter": "{value} " + yaxis_formatter,
|
||||
"rotate": yaxis_rotate,
|
||||
}
|
||||
},
|
||||
"min": yaxis_min,
|
||||
"max": yaxis_max
|
||||
}
|
||||
if is_convert:
|
||||
_yAxis.update(data=x_axis, type="category")
|
||||
|
||||
2
setup.py
2
setup.py
@ -9,7 +9,7 @@ except ImportError:
|
||||
__title__ = 'pyecharts'
|
||||
__description__ = 'Python echarts, make charting easier'
|
||||
__url__ = 'https://github.com/chenjiandongx/pyecharts'
|
||||
__version__ = '0.1.9.1'
|
||||
__version__ = '0.1.9.2'
|
||||
__author__ = 'chenjiandongx'
|
||||
__author_email__ = 'chenjiandongx@qq.com'
|
||||
__license__ = 'MIT'
|
||||
|
||||
@ -63,3 +63,11 @@ def test_bar():
|
||||
bar.add("", attr, v1, is_datazoom_show=True, datazoom_type='inside', datazoom_range=[10, 25])
|
||||
bar.show_config()
|
||||
bar.render()
|
||||
|
||||
# bar_6
|
||||
attr = ["{}天".format(i) for i in range(20)]
|
||||
v1 = [random.randint(1, 20) for _ in range(20)]
|
||||
bar = Bar("坐标轴标签旋转示例")
|
||||
bar.add("", attr, v1, interval=0, xaxis_rotate=30, yaxis_rotate=30)
|
||||
bar.show_config()
|
||||
bar.render()
|
||||
|
||||
@ -1,52 +0,0 @@
|
||||
import sys
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
import nbformat
|
||||
|
||||
|
||||
PY2 = sys.version_info[0] == 2
|
||||
|
||||
if PY2 is False:
|
||||
from io import StringIO
|
||||
|
||||
|
||||
def _notebook_run(path):
|
||||
"""Execute a notebook via nbconvert and collect output.
|
||||
:returns (parsed nb object, execution errors)
|
||||
"""
|
||||
with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout:
|
||||
args = ["jupyter", "nbconvert", "--to", "notebook", "--execute",
|
||||
"--output", fout.name, path]
|
||||
subprocess.check_call(args)
|
||||
|
||||
fout.seek(0)
|
||||
if PY2 is False:
|
||||
content = fout.read().decode('utf-8')
|
||||
xio = StringIO(content)
|
||||
else:
|
||||
xio = fout
|
||||
nb = nbformat.read(xio, nbformat.current_nbformat)
|
||||
|
||||
errors = [output for cell in nb.cells if "outputs" in cell
|
||||
for output in cell["outputs"]
|
||||
if output.output_type == "error"]
|
||||
|
||||
return nb, errors
|
||||
|
||||
|
||||
def _verify_ipynb(ipynb_file):
|
||||
if PY2:
|
||||
print("Ignored ipynb tests in python 2")
|
||||
pass
|
||||
else:
|
||||
nb, errors = _notebook_run(ipynb_file)
|
||||
assert errors == []
|
||||
|
||||
|
||||
def test_notebook_use_case():
|
||||
_verify_ipynb('../document/notebook-use-case.ipynb')
|
||||
|
||||
|
||||
def test_scatter_3d():
|
||||
_verify_ipynb('../document/scatter3d.ipynb')
|
||||
Loading…
x
Reference in New Issue
Block a user