Use of Pyecharts (currently the latest version 1.9)

Hits: 0

This document details the relevant parameters

from pyecharts.charts import *
from pyecharts import *
import pandas as pd
from pyecharts.globals import ThemeType, SymbolType, ChartType
import warnings
warnings.filterwarnings("ignore")

#Data reading 
import pandas as pd
data = pd.read_excel( '../data/xlsx/House and Salary.xlsx' )
data.sample(3)

#Data loading 
x1 = data[ 'city' ].to_list()
 y1 = data[ 'average house price' ].to_list()

#Histogram

bar = Bar( 
    # Initialize configuration items (here is just theme settings) 
    init_opts = opts.InitOpts( 
        # Set chart theme 
        theme = ThemeType.LIGHT, 
        # Set chart width 
        width = '1000px', 
        # Set chart height 
        height = '500px ', 
        # Set page title 
        page_title = 'City per capita salary', 
        # Set background color 
        bg_color = '#FFFFFF' 
    )) 
# Global configuration 
bar.set_global_opts( 
    # Toolbox global configuration 
    toolbox_opts = opts.ToolboxOpts( 
        # Set whether to display pictures 
        is_show = True, 
        pos_left ='70%', 
        pos_top = '20%', 
        # Set the series properties of the toolbox 
        feature = opts.ToolBoxFeatureOpts( 
            # Set the toolbox to save the image configuration item 
            save_as_image = opts.ToolBoxFeatureSaveAsImageOpts( 
                # Set the format of the saved image 
                type_ = 'jpg ', 
                # Set the name of the saved image 
                name = 'bar001', 
                # Set the background color 
                background_color = '#FFFFCC', 
                # Whether the setting is valid 
                is_show = True, 
                # Resolution setting 
                pixel_ratio = 2, 
            ) 
        ) 
    ), 
    # Title configuration item 
    title_opts= opts.TitleOpts( 
        # set title 
        title = 'city per capita salary', 
        # set position 
        pos_left = '42%', 
        # title style configuration 
        title_textstyle_opts = opts.TextStyleOpts( 
            # set font color 
            color = '#FF9933', 
            # set font 
            font_family = 'bold', 
            # set the title size 
            font_size = '25' 
        ) 
    ), 
    # set the legend style 
    legend_opts = opts.LegendOpts( 
        # set the legend type 
        type_ = 'plain', 
        # set whether the legend is displayed 
        is_show = True,
        # set position 
        pos_top = '10%', 
        pos_left = '70%' 
    ), 
    # visual map configuration 
    visualmap_opts = opts.VisualMapOpts( 
        # set whether to show 
        is_show = True, 
        # set max and min 
        min_ = 1000, 
        max_ = 8000, 
        # set title 
        range_text = ['max', 'min'], 
        # set position 
        pos_left = '0%', 
        pos_top = '50%', 
        # set orientation (horizontal/vertical) 
        orient = 'vertical' 
    ), 
    # prompt box Configuration item 
    tooltip_opts =opts.TooltipOpts( 
        # Set whether to display 
        is_show = True, 
        # Set trigger mode 
        trigger_on = 'mousemove', 
        # Set tooltip background color 
        background_color = '#FFFFCC', 
        # Set tooltip text style 
        textstyle_opts = opts.TextStyleOpts( 
            color = ' #000000', 
        ) 
    ), 
    # axis settings 
    xaxis_opts = opts.AxisOpts( 
        axisline_opts = opts.AxisLineOpts( 
            # axis display property 
            is_show = True, 
            # axis arrow points 
            symbol = ['none', 'arrow'] 
        ) 
    )
) 
bar.add_xaxis(x1) 
bar.add_yaxis('salary per capita',  y1) 
bar.render_notebook()

The data is of little significance. If the friend needs it, you can send a private message to QQ: 2545938497

You may also like...

Leave a Reply

Your email address will not be published.