Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to draw pictographic bar chart by Python Pyecharts

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today I will show you how to draw a pictographic bar chart by Python Pyecharts. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.

In the process of visual display, in order to achieve a more vivid display effect, we often need to customize some intuitive legends. Let's introduce the pictographs in the visualization library Pyecharts. I hope it will be helpful to you.

1. Preparation 1.1Import module from pyecharts import options as optsfrom pyecharts.charts import PictorialBarfrom pyecharts.globals import SymbolType

If you don't have pyecharts installed, just install pip.

1.2 partial parameter def add_yaxis (# series name series_name: str, # series data y_axis: Sequence, # graphic type symbol: Optional [str] = None, # graphic size symbol_size: Union [Numeric, Sequence, None] = None, # graphic location symbol_pos: Optional [str] = None # offset of graphics from original position symbol_offset: Optional [Sequence] = None, # rotation angle of graphics symbol_rotate: Optional [Numeric] = None, # whether to clip graphics is_symbol_clip: bool = False, # series label colors color: Optional [str] = None, # distance between columns of the same series Default is 10% of the category spacing. You can set a fixed value of category_gap: Union [Numeric, str] = "10%", # tag configuration item, refer to `series_ options.LabelOpts` label_opts: Union [opts.LabelOpts, dict] = opts.LabelOpts (),) 2. Basic pictogram

Population of some provinces and cities:

Province = ["Beijing", "Tianjin", "Hubei", "Shanxi", "Shanghai", "Inner Mongolia", "Yunnan", "Heilongjiang", "Guangdong", "Fujian"] values = [2189, 1386, 5775, 3491, 2487, 2404, 4720, 3185, 12601, 4154] c = (PictorialBar () .add _ xaxis (province) .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.ARROW,) .reversal _ axis () .set _ global_opts (title_opts=opts.TitleOpts (title= "provincial population (10,000)"), xaxis_opts=opts.AxisOpts (is_show=True) Yaxis_opts=opts.AxisOpts (axistick_opts=opts.AxisTickOpts (is_show=False), axisline_opts=opts.AxisLineOpts (linestyle_opts=opts.LineStyleOpts (opacity=0)),),) c.render_notebook ()

Effect:

Symbol styles are available: RECT, ROUND_RECT, TRIANGLE, DIAMOND, ARROW.

The effect of setting to "DIAMOND" is as follows:

3. Custom Legend 3.1 Image Legend

3.2 generate pictographs

Code:

C = (PictorialBar () .add _ xaxis (list (dic.keys () .add _ yaxis ("2020", [{"value": 18, "symbol": dic ['plane']}, {"value": 40, "symbol": dic ['train']}, {"value": 78, "symbol": dic ['car']}) {"value": 66, "symbol": dic ['ship']},], label_opts=opts.LabelOpts (is_show=False), symbol_size=22, symbol_repeat= "fixed", symbol_offset= [0,5], is_symbol_clip=True,) .add _ yaxis ("2021", [{"value": 54) "symbol": dic ['plane']}, {"value": 68, "symbol": dic ['train']}, {"value": 105, "symbol": dic ['car']}, {"value": 73, "symbol": dic ['ship']},], 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= "urban transport"), 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)),) c.render_notebook ()

Effect:

What are the five characteristics of python? what are the five characteristics of python: 1. It's easy to learn, and when you develop a program, you focus on solving problems, not understanding the language itself. two。 Object-oriented, compared with other major languages such as C++ and Java, Python implements object-oriented programming in a very powerful and simple way. 3. Portability, Python programs can run on a variety of platforms without modification. 4. Explanation, programs written in Python do not need to be compiled into binary code and can be run directly from the source code. 5. Open source, Python is one of FLOSS (Free / Open Source Software).

These are all the contents of how Python Pyecharts draws pictographs. For more information about how Python Pyecharts draws pictographs, you can search the previous articles or browse the following articles to learn! I believe the editor will add more knowledge to you. I hope you can support it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report