├── .gitignore ├── LICENSE ├── README.md ├── echartlib.py └── images ├── area.png ├── bar.png ├── line.png └── pie.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 ZekangLi 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # echart-plotlib 2 | A simple api for using echart in jupyter notebook. You can use these apis to plot line, stack, bar or pie. It's just for daily simple use. Welcome to contribute other echart plot options. 3 | 4 | # How to use it? 5 | 6 | ```python 7 | # test in jupyter notebook 8 | from echartlib import echartlib 9 | from IPython.display import HTML 10 | echart = echartlib(width=800, height=450) 11 | # plot line, and you can choose stack or tiled, bar or line in the graph 12 | data_name = ["最高气温", "最低温度"] 13 | xAxis_data = ['周一','周二','周三','周四','周五','周六','周日'] 14 | yAxis_data = [[21, 21, 25, 23, 22, 23, 20], [11, 11, 15, 13, 12, 13, 10]] # two dimension 15 | HTML(echart.plot_line(data_name=data_name, xAxis_data=xAxis_data, yAxis_data=yAxis_data, title="天气")) 16 | 17 | # plot area, and you can choose stack or tiled, bar or area in the graph 18 | data_name = ["最高气温", "最低温度"] 19 | xAxis_data = ['周一','周二','周三','周四','周五','周六','周日'] 20 | yAxis_data = [[21, 21, 25, 23, 22, 23, 20], [11, 11, 15, 13, 12, 13, 10]] #two dimension 21 | HTML(echart.plot_else(data_name=data_name, xAxis_data=xAxis_data, yAxis_data=yAxis_data, title="天气")) 22 | 23 | # plot pie 24 | data_name = ["最高气温", "最低温度"] 25 | data = [10, 20] 26 | HTML(echart.plot_pie(data_name=data_name, data=data, title="天气")) 27 | ``` 28 | 29 | # Example 30 | 31 | - pie 32 | 33 | ![pie](./images/pie.png) 34 | 35 | - line 36 | 37 | ![line](./images/line.png) 38 | 39 | - stack bar 40 | 41 | ![bar](./images/bar.png) 42 | 43 | - stack area 44 | 45 | ![area](./images/area.png) 46 | 47 | -------------------------------------------------------------------------------- /echartlib.py: -------------------------------------------------------------------------------- 1 | 2 | # coding: utf-8 3 | 4 | # In[1]: 5 | 6 | 7 | from IPython.display import HTML 8 | 9 | 10 | # In[27]: 11 | 12 | 13 | class echartlib(object): 14 | def __init__(self, width=600, height=450): 15 | self.head = """ 16 | 17 |
18 | 33 | """ 34 | 35 | def plot_else(self, data_name, xAxis_data, yAxis_data, title=None): 36 | option = { 37 | "title" : { 38 | "text": '', 39 | "subtext": "", 40 | "x":"center" 41 | }, 42 | "calculable" : "true", 43 | "legend": { 44 | "x":"right", 45 | "orient" : 'vertical', 46 | "data":["CLPRB"], 47 | "textStyle": { 48 | "fontSize": 12 49 | } 50 | }, 51 | "series" : [ 52 | { 53 | "name":"CLPRB", 54 | "type":"line", 55 | "stack": "总量", 56 | "itemStyle": {"normal": {"areaStyle": {"type": "default"}, "label": {"textStyle": {"fontSize": 20}}}}, 57 | "data":[] 58 | } 59 | ], 60 | "toolbox": { 61 | "x":'left', 62 | "show" :"true", 63 | "orient":"vertical", 64 | "feature" : { 65 | "mark" : {"show": "false"}, 66 | "dataView" : {"show": "false", "readOnly": "false"}, 67 | "magicType" : {"show": "false", "type": ["line", "stack", "tiled", "bar"]}, 68 | "restore" : {"show": "false"}, 69 | "saveAsImage" : {"show": "true"} 70 | } 71 | }, 72 | "tooltip" : { 73 | "trigger": "axis" 74 | }, 75 | 76 | "xAxis" : [ 77 | { 78 | "type" : "category", 79 | "boundaryGap" : "false", 80 | "data" : [] 81 | } 82 | ], 83 | "yAxis" : [ 84 | { 85 | "type" : "value" 86 | } 87 | ] 88 | } 89 | if title: 90 | option["title"]["text"] = title 91 | option["legend"]["data"] = data_name 92 | option["xAxis"][0]["data"] = xAxis_data 93 | series = [] 94 | 95 | for i in range(len(data_name)): 96 | series_per = { 97 | "name":"", 98 | "type":'line', 99 | "stack": '总量', 100 | "itemStyle": {"normal": {"areaStyle": {"type": 'default'}}}, 101 | "data":[] 102 | } 103 | series_per["name"] = data_name[i] 104 | series_per["data"] = yAxis_data[i] 105 | series.append(series_per) 106 | option["series"] = series 107 | return self.head+"option="+str(option)+self.tail 108 | 109 | def plot_line(self, data_name, xAxis_data, yAxis_data, title=None): 110 | option = { 111 | "title" : { 112 | "text": '', 113 | "subtext": "", 114 | "x":"center" 115 | }, 116 | "tooltip" : { 117 | "trigger": 'axis' 118 | }, 119 | "legend": { 120 | "x":"right", 121 | "orient" : 'vertical', 122 | "data":['最高气温'], 123 | "textStyle": { 124 | "fontSize": 12 125 | } 126 | }, 127 | "toolbox": { 128 | "x":'left', 129 | "show" : "true", 130 | "orient":"vertical", 131 | "feature" : { 132 | "mark" : {"show": "true"}, 133 | "dataView" : {"show": "true", "readOnly": "false"}, 134 | "magicType" : {"show": "true", "type": ['line', 'bar',"tiled"]}, 135 | "restore" : {"show": "true"}, 136 | "saveAsImage" : {"show": "true"} 137 | } 138 | }, 139 | "calculable" : "true", 140 | "xAxis" : [ 141 | { 142 | "type" : 'category', 143 | "boundaryGap" : "false", 144 | "data" : ['周一','周二','周三','周四','周五','周六','周日'] 145 | } 146 | ], 147 | "yAxis" : [ 148 | { 149 | "type" : 'value' 150 | } 151 | ], 152 | "series" : [ 153 | { 154 | "name":'最高气温', 155 | "type":'line', 156 | "data":[11, 11, 15, 13, 12, 13, 10] 157 | } 158 | ] 159 | } 160 | if title: 161 | option["title"]["text"] = title 162 | option["legend"]["data"] = data_name 163 | option["xAxis"][0]["data"] = xAxis_data 164 | series = [] 165 | for i in range(len(data_name)): 166 | series_per = { 167 | "name":"", 168 | "type":'line', 169 | "data":[] 170 | } 171 | series_per["name"] = data_name[i] 172 | series_per["data"] = yAxis_data[i] 173 | series.append(series_per) 174 | option["series"] = series 175 | return self.head+"option="+str(option)+self.tail 176 | 177 | def plot_pie(self, data_name, data, title=None): 178 | option = { 179 | "title" : { 180 | "text": '', 181 | "subtext": '', 182 | "x":'center' 183 | }, 184 | "tooltip" : { 185 | "trigger": 'item', 186 | "formatter": "{a}
{b} : {c} ({d}%)" 187 | }, 188 | "legend": { 189 | 190 | "orient" : 'vertical', 191 | "x":'right', 192 | "data":[] 193 | }, 194 | "toolbox": { 195 | "x":'left', 196 | "orient" : 'vertical', 197 | "show" : "true", 198 | "feature" : { 199 | "mark" : {"show": "true"}, 200 | "dataView" : {"show": "true", "readOnly": "false"}, 201 | "magicType" : { 202 | "show": "true", 203 | "type": ['pie'] 204 | }, 205 | "restore" : {"show": "true"}, 206 | "saveAsImage" : {"show": "true"} 207 | } 208 | }, 209 | "calculable" : "true", 210 | "series" : [ 211 | { 212 | "name": "", 213 | "type":'pie', 214 | "radius" : '55%', 215 | "center": ['50%', '60%'], 216 | "data":[] 217 | } 218 | ] 219 | } 220 | option["legend"]["data"] = data_name 221 | series_data = [] 222 | for i in range(len(data_name)): 223 | temp = {} 224 | temp["value"] = int(data[i]) 225 | temp["name"] = data_name[i] 226 | series_data.append(temp) 227 | option["series"][0]["data"] = series_data 228 | return self.head+"option="+str(option)+self.tail 229 | 230 | -------------------------------------------------------------------------------- /images/area.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lizekang/echart-plotlib/2bbd2765a2fa0f03ece9eb6fb846c4d1b5534961/images/area.png -------------------------------------------------------------------------------- /images/bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lizekang/echart-plotlib/2bbd2765a2fa0f03ece9eb6fb846c4d1b5534961/images/bar.png -------------------------------------------------------------------------------- /images/line.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lizekang/echart-plotlib/2bbd2765a2fa0f03ece9eb6fb846c4d1b5534961/images/line.png -------------------------------------------------------------------------------- /images/pie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lizekang/echart-plotlib/2bbd2765a2fa0f03ece9eb6fb846c4d1b5534961/images/pie.png --------------------------------------------------------------------------------