Pyecharts notes - Cartesian chart 2 (other than bar)

70.13 Line - Multiple_x_axes

link

import pyecharts.options as opts
from pyecharts.charts import Line

# Will be changed in v1.1.0
from pyecharts.commons.utils import JsCode

"""
Gallery use pyecharts 1.0.0
 Reference address: https://echarts.apache.org/examples/editor.html?c=multiple-x-axis

Functions that cannot be realized at present:

1,Not yet
"""

js_formatter = """function (params) {
        console.log(params);
        return 'precipitation  ' + params.value + (params.seriesData.length ? ': ' + params.seriesData[0].data : '');
    }"""

(
    Line(init_opts=opts.InitOpts(width="1600px", height="800px"))
    .add_xaxis(
        xaxis_data=[
            "2016-1",
            "2016-2",
            "2016-3",
            "2016-4",
            "2016-5",
            "2016-6",
            "2016-7",
            "2016-8",
            "2016-9",
            "2016-10",
            "2016-11",
            "2016-12",
        ]
    )
    .extend_axis(
        xaxis_data=[
            "2015-1",
            "2015-2",
            "2015-3",
            "2015-4",
            "2015-5",
            "2015-6",
            "2015-7",
            "2015-8",
            "2015-9",
            "2015-10",
            "2015-11",
            "2015-12",
        ],
        xaxis=opts.AxisOpts(
            type_="category",
            axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
            axisline_opts=opts.AxisLineOpts(
                is_on_zero=False, linestyle_opts=opts.LineStyleOpts(color="#6e9ef1")
            ),
            axispointer_opts=opts.AxisPointerOpts(
                is_show=True, label=opts.LabelOpts(formatter=JsCode(js_formatter))
            ),
        ),
    )
    .add_yaxis(
        series_name="2015 precipitation",
        is_smooth=True,
        symbol="emptyCircle",
        is_symbol_show=False,
        # xaxis_index=1,
        color="#d14a61",
        y_axis=[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
        label_opts=opts.LabelOpts(is_show=False),
        linestyle_opts=opts.LineStyleOpts(width=2),
    )
    .add_yaxis(
        series_name="2016 precipitation",
        is_smooth=True,
        symbol="emptyCircle",
        is_symbol_show=False,
        color="#6e9ef1",
        y_axis=[3.9, 5.9, 11.1, 18.7, 48.3, 69.2, 231.6, 46.6, 55.4, 18.4, 10.3, 0.7],
        label_opts=opts.LabelOpts(is_show=False),
        linestyle_opts=opts.LineStyleOpts(width=2),
    )
    .set_global_opts(
        legend_opts=opts.LegendOpts(),
        tooltip_opts=opts.TooltipOpts(trigger="none", axis_pointer_type="cross"),
        xaxis_opts=opts.AxisOpts(
            type_="category",
            axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
            axisline_opts=opts.AxisLineOpts(
                is_on_zero=False, linestyle_opts=opts.LineStyleOpts(color="#d14a61")
            ),
            axispointer_opts=opts.AxisPointerOpts(
                is_show=True, label=opts.LabelOpts(formatter=JsCode(js_formatter))
            ),
        ),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            splitline_opts=opts.SplitLineOpts(
                is_show=True, linestyle_opts=opts.LineStyleOpts(opacity=1)
            ),
        ),
    )
    .render("multiple_x_axes.html")
)

70.14 Line - Stacked_area_chart

link

import pyecharts.options as opts
from pyecharts.charts import Line

"""
Gallery use pyecharts 1.1.0
 Reference address: https://echarts.apache.org/examples/editor.html?c=area-stack

Functions that cannot be realized at present:

Not yet
"""


x_data = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
y_data = [820, 932, 901, 934, 1290, 1330, 1320]


(
    Line()
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis(
        series_name="Mail marketing",
        stack="total",
        y_axis=[120, 132, 101, 134, 90, 230, 210],
        areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
    )
    .add_yaxis(
        series_name="Alliance advertising",
        stack="total",
        y_axis=[220, 182, 191, 234, 290, 330, 310],
        areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
    )
    .add_yaxis(
        series_name="Video advertising",
        stack="total",
        y_axis=[150, 232, 201, 154, 190, 330, 410],
        areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
    )
    .add_yaxis(
        series_name="Direct access",
        stack="total",
        y_axis=[320, 332, 301, 334, 390, 330, 320],
        areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
    )
    .add_yaxis(
        series_name="Search Engines",
        stack="total",
        y_axis=[820, 932, 901, 934, 1290, 1330, 1320],
        areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
        label_opts=opts.LabelOpts(is_show=True, position="top"),
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Stacking area map"),
        tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            axistick_opts=opts.AxisTickOpts(is_show=True),
            splitline_opts=opts.SplitLineOpts(is_show=True),
        ),
        xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=False),
    )
    .render("stacked_area_chart.html")
)

70.15 Line - Line_step

link

import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker

c = (
    Line()
    .add_xaxis(Faker.choose())
    .add_yaxis("business A", Faker.values(), is_step=True)
    .set_global_opts(title_opts=opts.TitleOpts(title="Line-Stairs "))
    .render("line_step.html")
)

70.16 Line - Line_color_with_js_func

link

import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.commons.utils import JsCode


x_data = ["14", "15", "16", "17", "18", "19", "20", "21", "22", "23"]
y_data = [393, 438, 485, 631, 689, 824, 987, 1000, 1100, 1200]

background_color_js = (
    "new echarts.graphic.LinearGradient(0, 0, 0, 1, "
    "[{offset: 0, color: '#c86589'}, {offset: 1, color: '#06a7ff'}], false)"
)
area_color_js = (
    "new echarts.graphic.LinearGradient(0, 0, 0, 1, "
    "[{offset: 0, color: '#eb64fb'}, {offset: 1, color: '#3fbbff0d'}], false)"
)

c = (
    Line(init_opts=opts.InitOpts(bg_color=JsCode(background_color_js)))
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis(
        series_name="Total registered",
        y_axis=y_data,
        is_smooth=True,
        is_symbol_show=True,
        symbol="circle",
        symbol_size=6,
        linestyle_opts=opts.LineStyleOpts(color="#fff"),
        label_opts=opts.LabelOpts(is_show=True, position="top", color="white"),
        itemstyle_opts=opts.ItemStyleOpts(
            color="red", border_color="#fff", border_width=3
        ),
        tooltip_opts=opts.TooltipOpts(is_show=False),
        areastyle_opts=opts.AreaStyleOpts(color=JsCode(area_color_js), opacity=1),
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(
            title="OCTOBER 2015",
            pos_bottom="5%",
            pos_left="center",
            title_textstyle_opts=opts.TextStyleOpts(color="#fff", font_size=16),
        ),
        xaxis_opts=opts.AxisOpts(
            type_="category",
            boundary_gap=False,
            axislabel_opts=opts.LabelOpts(margin=30, color="#ffffff63"),
            axisline_opts=opts.AxisLineOpts(is_show=False),
            axistick_opts=opts.AxisTickOpts(
                is_show=True,
                length=25,
                linestyle_opts=opts.LineStyleOpts(color="#ffffff1f"),
            ),
            splitline_opts=opts.SplitLineOpts(
                is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f")
            ),
        ),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            position="right",
            axislabel_opts=opts.LabelOpts(margin=20, color="#ffffff63"),
            axisline_opts=opts.AxisLineOpts(
                linestyle_opts=opts.LineStyleOpts(width=2, color="#fff")
            ),
            axistick_opts=opts.AxisTickOpts(
                is_show=True,
                length=15,
                linestyle_opts=opts.LineStyleOpts(color="#ffffff1f"),
            ),
            splitline_opts=opts.SplitLineOpts(
                is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f")
            ),
        ),
        legend_opts=opts.LegendOpts(is_show=False),
    )
    .render("line_color_with_js_func.html")
)

70.17 Line - Smoothed_line_chart

link

import pyecharts.options as opts
from pyecharts.charts import Line

"""
Gallery use pyecharts 1.1.0
 Reference address: https://echarts.apache.org/examples/editor.html?c=line-smooth

Functions that cannot be realized at present:

Not yet
"""


x_data = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
y_data = [820, 932, 901, 934, 1290, 1330, 1320]


(
    Line()
    .set_global_opts(
        tooltip_opts=opts.TooltipOpts(is_show=False),
        xaxis_opts=opts.AxisOpts(type_="category"),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            axistick_opts=opts.AxisTickOpts(is_show=True),
            splitline_opts=opts.SplitLineOpts(is_show=True),
        ),
    )
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis(
        series_name="",
        y_axis=y_data,
        symbol="emptyCircle",
        is_symbol_show=True,
        is_smooth=True,
        label_opts=opts.LabelOpts(is_show=False),
    )
    .render("smoothed_line_chart.html")
)

70.18 Line - Line_markpoint_custom

link

import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker

x, y = Faker.choose(), Faker.values()
c = (
    Line()
    .add_xaxis(x)
    .add_yaxis(
        "business A",
        y,
        markpoint_opts=opts.MarkPointOpts(
            data=[opts.MarkPointItem(name="Custom marker point", coord=[x[2], y[2]], value=y[2])]
        ),
    )
    .set_global_opts(title_opts=opts.TitleOpts(title="Line-MarkPoint(Custom)"))
    .render("line_markpoint_custom.html")
)

70.19 Line - Distribution_of_electricity

link

import pyecharts.options as opts
from pyecharts.charts import Line

"""
Gallery use pyecharts 1.1.0
 Reference address: https://www.echartsjs.com/examples/editor.html?c=line-sections

Functions that cannot be realized at present:

1,visualMap Unable to set hidden temporarily
"""

x_data = [
    "00:00",
    "01:15",
    "02:30",
    "03:45",
    "05:00",
    "06:15",
    "07:30",
    "08:45",
    "10:00",
    "11:15",
    "12:30",
    "13:45",
    "15:00",
    "16:15",
    "17:30",
    "18:45",
    "20:00",
    "21:15",
    "22:30",
    "23:45",
]
y_data = [
    300,
    280,
    250,
    260,
    270,
    300,
    550,
    500,
    400,
    390,
    380,
    390,
    400,
    500,
    600,
    750,
    800,
    700,
    600,
    400,
]

(
    Line(init_opts=opts.InitOpts(width="1600px", height="800px"))
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis(
        series_name="Electricity consumption",
        y_axis=y_data,
        is_smooth=True,
        label_opts=opts.LabelOpts(is_show=False),
        linestyle_opts=opts.LineStyleOpts(width=2),
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Daily power consumption distribution", subtitle="It's pure fiction"),
        tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"),
        xaxis_opts=opts.AxisOpts(boundary_gap=False),
        yaxis_opts=opts.AxisOpts(
            axislabel_opts=opts.LabelOpts(formatter="{value} W"),
            splitline_opts=opts.SplitLineOpts(is_show=True),
        ),
        visualmap_opts=opts.VisualMapOpts(
            is_piecewise=True,
            dimension=0,
            pieces=[
                {"lte": 6, "color": "green"},
                {"gt": 6, "lte": 8, "color": "red"},
                {"gt": 8, "lte": 14, "color": "green"},
                {"gt": 14, "lte": 17, "color": "red"},
                {"gt": 17, "color": "green"},
            ],
        ),
    )
    .set_series_opts(
        markarea_opts=opts.MarkAreaOpts(
            data=[
                opts.MarkAreaItem(name="Morning peak", x=("07:30", "10:00")),
                opts.MarkAreaItem(name="Late peak", x=("17:30", "21:15")),
            ]
        )
    )
    .render("distribution_of_electricity.html")
)

70.20 Line - Beautiful_line_chart

link

import pyecharts.options as opts
from pyecharts.charts import Line, Grid
from pyecharts.commons.utils import JsCode

"""
Reference address: https://gallery.echartsjs.com/editor.html?c=xEyDk1hwBx
"""

x_data = ["14", "15", "16", "17", "18", "19", "20", "21", "22", "23"]
y_data = [393, 438, 485, 631, 689, 824, 987, 1000, 1100, 1200]

background_color_js = (
    "new echarts.graphic.LinearGradient(0, 0, 0, 1, "
    "[{offset: 0, color: '#c86589'}, {offset: 1, color: '#06a7ff'}], false)"
)
area_color_js = (
    "new echarts.graphic.LinearGradient(0, 0, 0, 1, "
    "[{offset: 0, color: '#eb64fb'}, {offset: 1, color: '#3fbbff0d'}], false)"
)

c = (
    Line(init_opts=opts.InitOpts(bg_color=JsCode(background_color_js)))
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis(
        series_name="Total registered",
        y_axis=y_data,
        is_smooth=True,
        is_symbol_show=True,
        symbol="circle",
        symbol_size=6,
        linestyle_opts=opts.LineStyleOpts(color="#fff"),
        label_opts=opts.LabelOpts(is_show=True, position="top", color="white"),
        itemstyle_opts=opts.ItemStyleOpts(
            color="red", border_color="#fff", border_width=3
        ),
        tooltip_opts=opts.TooltipOpts(is_show=False),
        areastyle_opts=opts.AreaStyleOpts(color=JsCode(area_color_js), opacity=1),
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(
            title="OCTOBER 2015",
            pos_bottom="5%",
            pos_left="center",
            title_textstyle_opts=opts.TextStyleOpts(color="#fff", font_size=16),
        ),
        xaxis_opts=opts.AxisOpts(
            type_="category",
            boundary_gap=False,
            axislabel_opts=opts.LabelOpts(margin=30, color="#ffffff63"),
            axisline_opts=opts.AxisLineOpts(is_show=False),
            axistick_opts=opts.AxisTickOpts(
                is_show=True,
                length=25,
                linestyle_opts=opts.LineStyleOpts(color="#ffffff1f"),
            ),
            splitline_opts=opts.SplitLineOpts(
                is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f")
            ),
        ),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            position="right",
            axislabel_opts=opts.LabelOpts(margin=20, color="#ffffff63"),
            axisline_opts=opts.AxisLineOpts(
                linestyle_opts=opts.LineStyleOpts(width=2, color="#fff")
            ),
            axistick_opts=opts.AxisTickOpts(
                is_show=True,
                length=15,
                linestyle_opts=opts.LineStyleOpts(color="#ffffff1f"),
            ),
            splitline_opts=opts.SplitLineOpts(
                is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f")
            ),
        ),
        legend_opts=opts.LegendOpts(is_show=False),
    )
)

(
    Grid()
    .add(
        c,
        grid_opts=opts.GridOpts(
            pos_top="20%",
            pos_left="10%",
            pos_right="10%",
            pos_bottom="15%",
            is_contain_label=True,
        ),
    )
    .render("beautiful_line_chart.html")
)

70.21 Line - Beijing_aqi (difficult)

link

70.22 Line - Line_style_and_item_style

link

import pyecharts.options as opts
from pyecharts.charts import Line

"""
Gallery use pyecharts 1.1.0
 Reference address: https://www.echartsjs.com/examples/editor.html?c=line-style

Functions that cannot be realized at present:

Not yet
"""


(
    Line(init_opts=opts.InitOpts(width="1280px", height="720px"))
    .add_xaxis(xaxis_data=["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"])
    .add_yaxis(
        series_name="",
        y_axis=[120, 200, 150, 80, 70, 110, 130],
        symbol="triangle",
        symbol_size=20,
        linestyle_opts=opts.LineStyleOpts(color="green", width=4, type_="dashed"),
        label_opts=opts.LabelOpts(is_show=False),
        itemstyle_opts=opts.ItemStyleOpts(
            border_width=3, border_color="yellow", color="blue"
        ),
    )
    .set_global_opts(
        xaxis_opts=opts.AxisOpts(type_="category"),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            axistick_opts=opts.AxisTickOpts(is_show=True),
            splitline_opts=opts.SplitLineOpts(is_show=True),
        ),
        tooltip_opts=opts.TooltipOpts(is_show=False),
    )
    .render("line_style_and_item_style.html")
)

70.23 Line - Line_markpoint

link

import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker

c = (
    Line()
    .add_xaxis(Faker.choose())
    .add_yaxis(
        "business A",
        Faker.values(),
        markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="min")]),
    )
    .add_yaxis(
        "business B",
        Faker.values(),
        markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max")]),
    )
    .set_global_opts(title_opts=opts.TitleOpts(title="Line-MarkPoint"))
    .render("line_markpoint.html")
)

70.24 Line - Line_markline

link

import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker

c = (
    Line()
    .add_xaxis(Faker.choose())
    .add_yaxis(
        "business A",
        Faker.values(),
        markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(type_="average")]),
    )
    .add_yaxis(
        "business B",
        Faker.values(),
        markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(type_="average")]),
    )
    .set_global_opts(title_opts=opts.TitleOpts(title="Line-MarkLine"))
    .render("line_markline.html")
)

70.25 Line - Line_itemstyle

link

import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker

c = (
    Line()
    .add_xaxis(xaxis_data=Faker.choose())
    .add_yaxis(
        "business A",
        Faker.values(),
        symbol="triangle",
        symbol_size=20,
        linestyle_opts=opts.LineStyleOpts(color="green", width=4, type_="dashed"),
        itemstyle_opts=opts.ItemStyleOpts(
            border_width=3, border_color="yellow", color="blue"
        ),
    )
    .set_global_opts(title_opts=opts.TitleOpts(title="Line-ItemStyle"))
    .render("line_itemstyle.html")
)

70.26 Line - Line_area_style

link

import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker

c = (
    Line()
    .add_xaxis(Faker.choose())
    .add_yaxis("business A", Faker.values(), areastyle_opts=opts.AreaStyleOpts(opacity=0.5))
    .add_yaxis("business B", Faker.values(), areastyle_opts=opts.AreaStyleOpts(opacity=0.5))
    .set_global_opts(title_opts=opts.TitleOpts(title="Line-Area map"))
    .render("line_area_style.html")
)

71.PictorialBar: pictographic bar

link

  • class pyecharts.charts.PictorialBar(RectChart)
class PictorialBar(
    # Initialize configuration items, refer to ` global_options.InitOpts`
    init_opts: opts.InitOpts = opts.InitOpts()
)
  • func pyecharts.charts.PictorialBar.add_yaxis
def add_yaxis(
    # Series name, used for displaying tooltip and legend filtering of legend.
    series_name: str,

    # Series data
    y_axis: Sequence,

    # Drawing type.
    # The tag types provided by ecarts include 'circle', 'rect', 'roundRect', 'triangle', 
    # 'diamond', 'pin', 'arrow', 'none'
    # Can pass' image://url 'set as a picture, where the URL is a link to the picture, or a dataURI.
    # URL is a picture link, for example: ' image://http://xxx.xxx.xxx/a/b.png '
    # The URL is a dataURI. For example: ' image://data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfO...
    # You can set the icon to any vector path through 'path: / /'. Compared with the way of using pictures, this method does not have to worry about aliasing or blurring due to scaling,
    # And can be set to any color. The path graph is adaptively resized. See SVG PathData for the format of the path.
    # You can edit and export from tools such as Adobe Illustrator. For example:
    # 'path://M30.9,53.2C16.8,53.2,5.3,41.7,5.3,27.6S16.8,2,30.9,2C45,2,56.4,13.5,56.4,2...'
    symbol: Optional[str] = None,

    # The size of the graph.
    # The width and height can be represented separately by an array. For example, [20, 10] indicates that the tag width is 20,
    # The height is 10, which can also be set to a single number such as 10, representing [10, 10].
    # It can be set as an absolute value (such as 10) or as a percentage (such as' 120% ', ['55%', 23]).
    symbol_size: Union[Numeric, Sequence, None] = None,

    # The location of the drawing. Available values:
    # 'start ': the edge of the figure is inscribed at the beginning of the column.
    # 'end': the edge of the figure is inscribed at the end of the column.
    # 'center': the figure is centered in the column.
    symbol_pos: Optional[str] = None,

    # The offset of the drawing from its original position. symbolOffset is the last calculation step in graphic positioning,
    # You can fine tune the calculated position of the graph.
    # It can be set as an absolute value (such as 10) or as a percentage (such as' 120% ', ['55%', 23]).
    # When set to percentage, it represents the percentage of symbolSize relative to its own size.
    # For example, [0, '- 50%'] is to move the figure upward by half its size.
    symbol_offset: Optional[Sequence] = None,

    # The rotation angle of the drawing.
    # Note that symbolRotate does not affect the positioning of the drawing (even beyond the boundary of the datum column), but simply rotates around its own center.
    # This attribute can be set at the root of the series, indicating that all data in the series is effective;
    # It can also be set in each data item in data, indicating that it is only effective for this data item.
    symbol_rotate: Optional[Numeric] = None,

    # Specifies whether drawing elements are duplicated. Values can be:
    # false/null/undefined: no repetition, that is, each data value is represented by a graphic element.
    # true: repeat graphic elements, that is, each data value is represented by a group of repeated graphic elements. The number of repetitions is calculated according to data.
    # a number: repeat graphic elements, that is, each data value is represented by a group of repeated graphic elements. The number of repetitions is a given constant value.
    # 'fixed': repeat graphic elements, that is, each data value is represented by a group of repeated graphic elements.
    # The number of repetitions is calculated based on symbolBoundingData, that is, it has nothing to do with data. This is useful when the figure is used as a background.
    symbol_repeat: Optional[str] = None,

    # Specifies the order in which drawing elements are drawn when they are repeated. This property is useful in two cases:
    # When symbolMargin is set to a negative value, repeated figures will overlap each other. This is because you can use symbolRepeatDirection to specify the overwrite order.
    # When animation delay or animation delayupdate is used, symbolRepeatDirection specifies the index order.
    # The value of this property can be: 'start' or 'end'.
    symbol_repeat_direction: Optional[str] = None,

    # The space between the two sides of the graph ("two sides" refers to both sides in the direction of its numerical axis). It can be an absolute value (such as 20) or a percentage value (such as' - 30% '),
    # Represents the percentage of symbolSize relative to its own size. It only makes sense when symbolRepeat is used.
    # It can be a positive value, indicating a large interval; It can also be negative. When symbolRepeat is used, negative numbers can make graphics overlap.
    # You can add a "!" at the end of its value, Such as "30%!" Or 25!, Indicates that the beginning of the first figure and the end of the last figure are left blank,
    # Not close to the boundary. The default is close to the boundary.
    symbol_margin: Union[Numeric, str, None] = None,

    # Whether to clip the drawing.
    # false/null/undefined: the graph itself represents the value size.
    # true: the remaining part of the figure after clipping represents the numerical size.
    # symbolClip is often used in this scenario to express "total value" and "current value" at the same time. In this scenario, two series can be used,
    # One series is a complete graph, which is used as the "background" to express the total value, and the other series is a graph clipped with symbolClip to express the current value.
    is_symbol_clip: bool = False,

    # Check legend
    is_selected: bool = True,

    # The x-axis index used is useful when there are multiple X-axes in a single chart instance.
    xaxis_index: Optional[Numeric] = None,

    # The y-axis index used is useful when there are multiple Y-axes in a single chart instance.
    yaxis_index: Optional[Numeric] = None,

    # Series label colors
    color: Optional[str] = None,

    # The distance between columns in the same series is 20% of the category spacing by default, and a fixed value can be set
    category_gap: Union[Numeric, str] = "20%",

    # The distance between columns of different series is a percentage (e.g. '30%', representing 30% of the column width).
    # If you want two series of columns to overlap, you can set gap to '- 100%'. This is useful when using columns as a background.
    gap: Optional[str] = None,

    # Label configuration item, refer to ` series_options.LabelOpts`
    label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(),

    # Marker point configuration item, refer to ` series_options.MarkPointOpts`
    markpoint_opts: Union[opts.MarkPointOpts, dict, None] = None,

    # Marker line configuration item, refer to ` series_options.MarkLineOpts`
    markline_opts: Union[opts.MarkLineOpts, dict, None] = None,

    # Prompt box component configuration item, refer to ` series_options.TooltipOpts`
    tooltip_opts: Union[opts.TooltipOpts, dict, None] = None,

    # Element style configuration item, refer to ` series_options.ItemStyleOpts`
    itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None,

    # You can define which dimension of data is encoded into what.
    encode: types.Union[types.JsCode, dict] = None,
)

71.1 Pictorialbar - Pictorialbar_base

link

from pyecharts import options as opts
from pyecharts.charts import PictorialBar
from pyecharts.globals import SymbolType

location = ["Shanxi", "Sichuan", "Tibet", "Beijing", "Shanghai", "Inner Mongolia", "Yunnan", "Heilongjiang", "Guangdong", "Fujian"]
values = [13, 42, 67, 81, 86, 94, 166, 220, 249, 262]

c = (
    PictorialBar()
    .add_xaxis(location)
    .add_yaxis(
        "",
        values,
        label_opts=opts.LabelOpts(is_show=False),
        symbol_size=18,
        symbol_repeat="fixed",
        symbol_offset=[0, 0],
        is_symbol_clip=True,
        symbol=SymbolType.ROUND_RECT,
    )
    .reversal_axis()
    .set_global_opts(
        title_opts=opts.TitleOpts(title="PictorialBar-Population of each province (false data)"),
        xaxis_opts=opts.AxisOpts(is_show=False),
        yaxis_opts=opts.AxisOpts(
            axistick_opts=opts.AxisTickOpts(is_show=False),
            axisline_opts=opts.AxisLineOpts(
                linestyle_opts=opts.LineStyleOpts(opacity=0)
            ),
        ),
    )
    .render("pictorialbar_base.html")
)

71.2 Pictorialbar - Pictorialbar_multi_custom_symbols

link

import json

from pyecharts import options as opts
from pyecharts.charts import PictorialBar

location = ["Shanxi", "Sichuan", "Tibet", "Beijing", "Shanghai", "Inner Mongolia", "Yunnan", "Heilongjiang", "Guangdong", "Fujian"]
values = [13, 42, 67, 81, 86, 94, 166, 220, 249, 262]


with open("symbol.json", "r", encoding="utf-8") as f:
    symbols = json.load(f)

c = (
    PictorialBar()
    .add_xaxis(["reindeer", "ship", "plane", "train", "car"])
    .add_yaxis(
        "2015",
        [
            {"value": 157, "symbol": symbols["reindeer"]},
            {"value": 21, "symbol": symbols["ship"]},
            {"value": 66, "symbol": symbols["plane"]},
            {"value": 78, "symbol": symbols["train"]},
            {"value": 123, "symbol": symbols["car"]},
        ],
        label_opts=opts.LabelOpts(is_show=False),
        symbol_size=22,
        symbol_repeat="fixed",
        symbol_offset=[0, 5],
        is_symbol_clip=True,
    )
    .add_yaxis(
        "2016",
        [
            {"value": 184, "symbol": symbols["reindeer"]},
            {"value": 29, "symbol": symbols["ship"]},
            {"value": 73, "symbol": symbols["plane"]},
            {"value": 91, "symbol": symbols["train"]},
            {"value": 95, "symbol": symbols["car"]},
        ],
        label_opts=opts.LabelOpts(is_show=False),
        symbol_size=22,
        symbol_repeat="fixed",
        symbol_offset=[0, -25],
        is_symbol_clip=True,
    )
    .reversal_axis()
    .set_global_opts(
        title_opts=opts.TitleOpts(title="PictorialBar-Vehicles in X City"),
        xaxis_opts=opts.AxisOpts(is_show=False),
        yaxis_opts=opts.AxisOpts(
            axistick_opts=opts.AxisTickOpts(is_show=False),
            axisline_opts=opts.AxisLineOpts(
                linestyle_opts=opts.LineStyleOpts(opacity=0)
            ),
        ),
    )
    .render("pictorialbar_multi_custom_symbols.html")
)

71.3 Pictorialbar - Pictorialbar_custom_symbol

link

import json

from pyecharts import options as opts
from pyecharts.charts import PictorialBar

location = ["Shanxi", "Sichuan", "Tibet", "Beijing", "Shanghai", "Inner Mongolia", "Yunnan", "Heilongjiang", "Guangdong", "Fujian"]
values = [13, 42, 67, 81, 86, 94, 166, 220, 249, 262]


with open("symbol.json", "r", encoding="utf-8") as f:
    symbols = json.load(f)


c = (
    PictorialBar()
    .add_xaxis(location)
    .add_yaxis(
        "",
        values,
        label_opts=opts.LabelOpts(is_show=False),
        symbol_size=22,
        symbol_repeat="fixed",
        symbol_offset=[0, -5],
        is_symbol_clip=True,
        symbol=symbols["boy"],
    )
    .reversal_axis()
    .set_global_opts(
        title_opts=opts.TitleOpts(title="PictorialBar-custom Symbol"),
        xaxis_opts=opts.AxisOpts(is_show=False),
        yaxis_opts=opts.AxisOpts(
            axistick_opts=opts.AxisTickOpts(is_show=False),
            axisline_opts=opts.AxisLineOpts(
                linestyle_opts=opts.LineStyleOpts(opacity=0)
            ),
        ),
    )
    .render("pictorialbar_custom_symbol.html")
)

72.Scatter: scatter chart

link

  • class pyecharts.charts.Scatter(RectChart)
class Scatter(
    # Initialize configuration items, refer to ` global_options.InitOpts`
    init_opts: opts.InitOpts = opts.InitOpts()
)
  • func pyecharts.charts.Scatter.add_yaxis
def add_yaxis(
    # Series name, used for displaying tooltip and legend filtering of legend.
    series_name: str,

    # Series data
    y_axis: Sequence,

    # Check legend
    is_selected: bool = True,

    # The x-axis index used is useful when there are multiple X-axes in a single chart instance.
    xaxis_index: Optional[Numeric] = None,

    # The y-axis index used is useful when there are multiple Y-axes in a single chart instance.
    yaxis_index: Optional[Numeric] = None,

    # Series label colors
    color: Optional[str] = None,

    # Marked graphics.
    # The tag types provided by ecarts include 'circle', 'rect', 'roundRect', 'triangle', 
    # 'diamond', 'pin', 'arrow', 'none'
    # Can pass' image://url 'set as a picture, where the URL is a link to the picture, or a dataURI.
    symbol: Optional[str] = None,

    # The size of the tag can be set to a single number such as 10, or the width and height can be separated by an array,
    # For example, [20, 10] indicates that the width of the mark is 20 and the height is 10.
    symbol_size: Numeric = 10,

    # The rotation angle of the marker. Note that in markLine, when symbol is' arrow ', the angle forced by symbol rotate to tangent will be ignored.
    symbol_rotate: types.Optional[types.Numeric] = None,

    # Label configuration item, refer to ` series_options.LabelOpts`
    label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(position="right"),

    # Marker point configuration item, refer to ` series_options.MarkPointOpts`
    markpoint_opts: Union[opts.MarkPointOpts, dict, None] = None,

    # Marker line configuration item, refer to ` series_options.MarkLineOpts`
    markline_opts: Union[opts.MarkLineOpts, dict, None] = None,

    # Chart label field is often used to mark the data of a range in the chart. Refer to ` series_options.MarkAreaOpts`
    markarea_opts: types.MarkArea = None,

    # Prompt box component configuration item, refer to ` series_options.TooltipOpts`
    tooltip_opts: Union[opts.TooltipOpts, dict, None] = None,

    # Element style configuration item, refer to ` series_options.ItemStyleOpts`
    itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None,

    # You can define which dimension of data is encoded into what.
    encode: types.Union[types.JSFunc, dict, None] = None,
)
  • ScatterItem: scatter chart data item
class ScatterItem(
    # Data item name.
    name: Union[str, Numeric] = None,

    # Data item value.
    value: Union[str, Numeric] = None,

    # A graph of a single data tag.
    # The tag types provided by ECharts include 
    # 'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow', 'none'
    # Can pass' image://url 'set as a picture, where the URL is a link to the picture, or a dataURI.
    # You can set the icon to any vector path through 'path: / /'.
    symbol: Optional[str] = None,

    # The size of a single data mark can be set to a single number such as 10
    # An array can also be used to separate the width and height. For example, [20, 10] indicates that the tag width is 20 and the height is 10.
    symbol_size: Union[Sequence[Numeric], Numeric] = None,

    # The rotation angle (not radians) of a single data marker. just
    symbol_rotate: Optional[Numeric] = None,

    # If the symbol is in the form of path: / /, whether to maintain the aspect ratio of the figure when zooming.
    symbol_keep_aspect: bool = False,

    # The offset of a single data marker from its original position.
    symbol_offset: Optional[Sequence] = None,

    # Label configuration item, refer to ` series_options.LabelOpts`
    label_opts: Union[LabelOpts, dict, None] = None,

    # Element style configuration item, refer to ` series_options.ItemStyleOpts`
    itemstyle_opts: Union[ItemStyleOpts, dict, None] = None,

    # Prompt box component configuration item, refer to ` series_options.TooltipOpts`
    tooltip_opts: Union[TooltipOpts, dict, None] = None,
)

72.1 Scatter - Basic_scatter_chart

link

import pyecharts.options as opts
from pyecharts.charts import Scatter

"""
Gallery use pyecharts 1.1.0
 Reference address: https://echarts.apache.org/examples/editor.html?c=scatter-simple

Functions that cannot be realized at present:

1,Not yet
"""

data = [
    [10.0, 8.04],
    [8.0, 6.95],
    [13.0, 7.58],
    [9.0, 8.81],
    [11.0, 8.33],
    [14.0, 9.96],
    [6.0, 7.24],
    [4.0, 4.26],
    [12.0, 10.84],
    [7.0, 4.82],
    [5.0, 5.68],
]
data.sort(key=lambda x: x[0])
x_data = [d[0] for d in data]
y_data = [d[1] for d in data]

(
    Scatter(init_opts=opts.InitOpts(width="1600px", height="1000px"))
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis(
        series_name="",
        y_axis=y_data,
        symbol_size=20,
        label_opts=opts.LabelOpts(is_show=False),
    )
    .set_series_opts()
    .set_global_opts(
        xaxis_opts=opts.AxisOpts(
            type_="value", splitline_opts=opts.SplitLineOpts(is_show=True)
        ),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            axistick_opts=opts.AxisTickOpts(is_show=True),
            splitline_opts=opts.SplitLineOpts(is_show=True),
        ),
        tooltip_opts=opts.TooltipOpts(is_show=False),
    )
    .render("basic_scatter_chart.html")
)

72.2 Scatter - Scatter_multi_dimension

link

from pyecharts import options as opts
from pyecharts.charts import Scatter
from pyecharts.commons.utils import JsCode
from pyecharts.faker import Faker

c = (
    Scatter()
    .add_xaxis(Faker.choose())
    .add_yaxis(
        "business A",
        [list(z) for z in zip(Faker.values(), Faker.choose())],
        label_opts=opts.LabelOpts(
            formatter=JsCode(
                "function(params){return params.value[1] +' : '+ params.value[2];}"
            )
        ),
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Scatter-Multidimensional data"),
        tooltip_opts=opts.TooltipOpts(
            formatter=JsCode(
                "function (params) {return params.name + ' : ' + params.value[2];}"
            )
        ),
        visualmap_opts=opts.VisualMapOpts(
            type_="color", max_=150, min_=20, dimension=1
        ),
    )
    .render("scatter_multi_dimension.html")
)

72.3 Scatter - Scatter_visualmap_color

link

from pyecharts import options as opts
from pyecharts.charts import Scatter
from pyecharts.faker import Faker

c = (
    Scatter()
    .add_xaxis(Faker.choose())
    .add_yaxis("business A", Faker.values())
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Scatter-VisualMap(Color)"),
        visualmap_opts=opts.VisualMapOpts(max_=150),
    )
    .render("scatter_visualmap_color.html")
)

72.4 Scatter - Scatter_splitline

link

from pyecharts import options as opts
from pyecharts.charts import Scatter
from pyecharts.faker import Faker

c = (
    Scatter()
    .add_xaxis(Faker.choose())
    .add_yaxis("business A", Faker.values())
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Scatter-Show split lines"),
        xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
        yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
    )
    .render("scatter_splitline.html")
)

72.5 Scatter - Scatter_visualmap_size

link

from pyecharts import options as opts
from pyecharts.charts import Scatter
from pyecharts.faker import Faker

c = (
    Scatter()
    .add_xaxis(Faker.choose())
    .add_yaxis("business A", Faker.values())
    .add_yaxis("business B", Faker.values())
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Scatter-VisualMap(Size)"),
        visualmap_opts=opts.VisualMapOpts(type_="size", max_=150, min_=20),
    )
    .render("scatter_visualmap_size.html")
)

73.Overlap: stacked multi graph

link

73.1 Overlap - Overlap_bar_line

link

from pyecharts import options as opts
from pyecharts.charts import Bar, Line
from pyecharts.faker import Faker

v1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
v2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
v3 = [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]


bar = (
    Bar()
    .add_xaxis(Faker.months)
    .add_yaxis("Evaporation", v1)
    .add_yaxis("precipitation", v2)
    .extend_axis(
        yaxis=opts.AxisOpts(
            axislabel_opts=opts.LabelOpts(formatter="{value} °C"), interval=5
        )
    )
    .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Overlap-bar+line"),
        yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter="{value} ml")),
    )
)

line = Line().add_xaxis(Faker.months).add_yaxis("average temperature", v3, yaxis_index=1)
bar.overlap(line)
bar.render("overlap_bar_line.html")

73.2 Overlap - Overlap_line_scatter

link

from pyecharts import options as opts
from pyecharts.charts import Line, Scatter
from pyecharts.faker import Faker

x = Faker.choose()
line = (
    Line()
    .add_xaxis(x)
    .add_yaxis("business A", Faker.values())
    .add_yaxis("business B", Faker.values())
    .set_global_opts(title_opts=opts.TitleOpts(title="Overlap-line+scatter"))
)
scatter = (
    Scatter()
    .add_xaxis(x)
    .add_yaxis("business A", Faker.values())
    .add_yaxis("business B", Faker.values())
)
line.overlap(scatter)
line.render("overlap_line_scatter.html")

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

70.15

link

Tags: echarts

Posted on Wed, 01 Sep 2021 20:16:14 -0400 by kfir91