Theme customization: Expand the theme plugin, diversified chart color matching. V0.5.2+ added

Since 0.5.2+, pyecharts has supported the replacement of themes. The following is an example of replacing with "dark":

import random

from pyecharts import Bar


X_AXIS = ["T-shirt", "Sweater", "Georgette", "Trousers", "High-heels", "Socks"]
bar = Bar("My first chart", "For our fashion shop client")
bar.use_theme("dark")
bar.add("Debenhams", X_AXIS, [random.randint(10, 100) for _ in range(6)])
bar.add("Marks & Spencer", X_AXIS, [random.randint(10, 100) for _ in range(6)])
bar.add("Premark", X_AXIS, [random.randint(10, 100) for _ in range(6)])
bar.add("TK Maxx", X_AXIS, [random.randint(10, 100) for _ in range(6)])
bar.render()

dark

Default theme effect

default

Theme plugins usage

ECharts comes with the dark theme, and pyecharts comes with dark.
echarts-themes-pypkg theme plugin provides the following topics :

Installing theme plugin

$ pip install echarts-themes-pypkg

Theme usage

Replace a single graphic theme

bar.use_theme("vintage")

Replace all chart topics in the operating environment

from pyecharts import configure

# Put this line of code in the header
configure(global_theme='dark')

bar = Bar()
# other code

Example

vintage

vintage

macarons

macarons

infographic

infographic

shine

shine

roma

roma

westeros

westeros

wonderland

wonderland

chalk

chalk

halloween

halloween

essos

essos

walden

walden

purple-passion

purple-passion

romantic

romantic

Use your own built theme

ECharts provides Theme Build Tools, from which you can build favorite themes like myTheme.js. Then hack the echarts-themes-pypkg package. The specific operation is as follows

  1. cd to your Python installation environment Lib/site-packages/echarts_themes_pypkg/resources. The specific path varies by operating system
  2. Move myTheme.js to resources/echarts-themes-js folder
  3. Change the resources/registry.json file
"PINYIN_MAP": {
        "shine": "shine",
        ...
        "myTheme": "myTheme"    # here
    },
    "FILE_MAP": {
        "shine": "shine",
        ...
        "myTheme": "myTheme"    # and here
    }
  1. cd to jupyter/nbextensions/echarts-themes-js directory in the notebook installation environment, the specific path varies by operating system
  2. Move myTheme.js to echarts-themes-js folder
  3. Use chart.use_theme("myTheme")

4、5 as options, you can ignore this step if you don't use a notebook.