{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 11.1 组合图表组件"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 组合组件 Grid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 准备子图\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Grid, Line, Scatter\n",
    "from pyecharts.faker import Faker\n",
    "\n",
    "x_data = Faker.choose()\n",
    "y_data1 = Faker.values()\n",
    "y_data2 = Faker.values()\n",
    "\n",
    "scatter = (\n",
    "    Scatter(\n",
    "        init_opts=opts.InitOpts(width='500px')\n",
    "    )\n",
    "    .add_xaxis(x_data)\n",
    "    .add_yaxis(\"组A\", y_data1)\n",
    "    .add_yaxis(\"组B\", y_data2)\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"散点图\"),\n",
    "        legend_opts=opts.LegendOpts(pos_left=\"20%\"),\n",
    "    )\n",
    ")\n",
    "\n",
    "line = (\n",
    "    Line(\n",
    "        init_opts=opts.InitOpts(width='500px')\n",
    "    )\n",
    "    .add_xaxis(x_data)\n",
    "    .add_yaxis(\"组A\", y_data1)\n",
    "    .add_yaxis(\"组B\", y_data2)\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"折线图\", pos_right=\"5%\"),\n",
    "        legend_opts=opts.LegendOpts(pos_right=\"20%\"),\n",
    "    )\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 水平布局\n",
    "(\n",
    "    Grid()\n",
    "    .add(scatter, grid_opts=opts.GridOpts(pos_right=\"55%\"))\n",
    "    .add(line, grid_opts=opts.GridOpts(pos_left=\"55%\"))\n",
    ").render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 垂直布局\n",
    "(\n",
    "    Grid()\n",
    "    .add(scatter, grid_opts=opts.GridOpts(pos_bottom=\"55%\"))\n",
    "    .add(line, grid_opts=opts.GridOpts(pos_top=\"55%\"))\n",
    ").render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 任意布局\n",
    "(\n",
    "    Grid()\n",
    "    .add(scatter, grid_opts=opts.GridOpts(pos_top=\"50%\", pos_right=\"50%\"))\n",
    "    .add(line, grid_opts=opts.GridOpts(pos_bottom=\"50%\", pos_left=\"50%\"))\n",
    ").render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 页面组件 Page"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.charts import Page\n",
    "\n",
    "(\n",
    "    Page(\n",
    "#         layout=Page.SimplePageLayout\n",
    "        layout=Page.DraggablePageLayout\n",
    "    )\n",
    "    .add(\n",
    "        scatter,\n",
    "        line)\n",
    ").render('simple_page.html')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 分页组件 Tab"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.charts import Tab\n",
    "\n",
    "(\n",
    "    Tab()\n",
    "    .add(scatter, \"散点图\")\n",
    "    .add(line, \"折线图\")\n",
    ").render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 11.2 仪表盘相关图表"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 仪表盘"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.charts import Gauge\n",
    "\n",
    "(\n",
    "    Gauge()\n",
    "    .add(\"\", \n",
    "         [(\"完成率\", 66.6)],\n",
    "        radius=\"70%\",\n",
    "         title_label_opts=opts.GaugeTitleOpts(offset_center=[0, \"30%\"]),\n",
    "         detail_label_opts=opts.GaugeDetailOpts(offset_center=[0, \"-50%\"]),\n",
    "    )\n",
    ").render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 水球图 Liquid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.charts import Liquid\n",
    "\n",
    "(\n",
    "    Liquid()\n",
    "    .add(\"\", \n",
    "         [0.6, 0.7],\n",
    "#          shape='circle',\n",
    "#          shape='rect',\n",
    "#          shape='triangle',\n",
    "    )\n",
    ").render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 主题设置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.globals import ThemeType\n",
    "\n",
    "(\n",
    "    Line(\n",
    "        init_opts=opts.InitOpts(\n",
    "#             theme=ThemeType.LIGHT\n",
    "            theme=ThemeType.DARK\n",
    "#             theme=ThemeType.PURPLE_PASSION\n",
    "        )\n",
    "    )\n",
    "    .add_xaxis(x_data)\n",
    "    .add_yaxis(\"组A\", y_data1)\n",
    "    .add_yaxis(\"组B\", y_data2)\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"折线图\", pos_right=\"5%\"),\n",
    "        legend_opts=opts.LegendOpts(pos_right=\"20%\"),\n",
    "    )\n",
    ").render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "data_anal_env",
   "language": "python",
   "name": "data_anal_env"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
