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 histogram by pyecharts in Python

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the Python pyecharts how to draw a bar chart, the article is very detailed, has a certain reference value, interested friends must read it!

First, a brief introduction to the syntax of pyecharts bar chart drawing.

A column / bar chart that represents the size of the data by the height of the column / the width of the bar.

Bar.add () method signature:

Add (name, x_axis, y_axis

Is_stack=False

Bar_category_gap='20%', * * kwargs)

Name- > str legend name

X axis data-> list x axis data

Y axis-> list y axis data

Is_stack- > bool data stack. Stack values with the same series configuration on the same category axis can be stacked.

Bar_category_gap- > the column distance of the int/str axis, which is next to the column when set to 0 (histogram type). The default is'20%'.

The value of mark_point marked point is: average min max

The value of mark_line tag line is: average min max

Is_convert=True x-axis and y-axis exchange

Is_label_show=True display data label

Xaxis_rotate=30, yaxis_rotate=30 rotation x-axis or y-axis label

Label_color sets the column color

Second, draw an ordinary bar chart

From pyecharts import Bar#Note: the global configuration item should be set on the last add (), otherwise the side setting will be washed out. Attr = ["shirt", "cardigan", "chiffon shirt", "trousers", "high heels", "socks", "mattress"] v1 = [5, 20, 36, 10, 75, 90, 30] v2 = [10, 25, 8, 60, 20, 80, 50] bar = Bar ("sample stacking of bar chart data") # sets the title bar.add ("Merchant A", attr, v1 markmarks point = ["average"] Is_label_show=True) bar.add ("merchant B", attr, v2 min markup line = ["min", "max"], is_label_show=True) bar.render (ritual C:\ Users\ ASUS\ Desktop\ restart\ Python use pyecharts drawing\ bar chart 1.html') # generate HTML file

Third, draw a stacked column chart

From pyecharts import Bar#Note: the global configuration item should be set on the last add (), otherwise the side setting will be washed out. # is_stack- > bool data Stack Attr = [shirts "," woolen sweaters "," chiffon shirts "," trousers "," high heels "," socks "," mattresses "] v1 = [5, 20, 36, 10, 75, 90, 30] v2 = [10, 25, 8, 60, 20, 80] can be stacked with the same stack values on the same axis. 50] bar = Bar ("histogram data stacking example") # set the title bar.add ("Merchant A", attr, v1 Markmark pointpoint = ["average"], is_label_show=True,is_stack=True) bar.add ("Merchant B", attr, v2 Markmark line = ["min", "max"], is_label_show=True Is_stack=True) bar.render (ritual C:\ Users\ ASUS\ Desktop\ restart\ Python use pyecharts drawing\ bar chart 1.html') # generate the HTML file

Fourth, draw a horizontal column chart

From pyecharts import Bar#is_convert=True x-axis and y-axis exchange # Note: the global configuration item should be set on the last add (), otherwise the side setting will be washed out. Attr = ["shirt", "cardigan", "chiffon shirt", "trousers", "high heels", "socks", "mattress"] v1 = [5, 20, 36, 10, 75, 90, 30] v2 = [10, 25, 8, 60, 20, 80, 50] bar = Bar ("sample stacking of bar chart data") # sets the title bar.add ("Merchant A", attr, v1 markmarks point = ["average"], is_label_show=True Is_convert=True) bar.add ("merchant B", attr, v2 min markup line = ["min", "max"], is_label_show=True,is_convert=True) bar.render (ritual C:\ Users\ ASUS\ Desktop\ restart\ Python use pyecharts drawing\ bar chart 1.html') # generate HTML file

5. Pyecharts bar chart datazoom case

6. I put together the code corresponding to the datazoom case of pyecharts bar chart with page.

# coding=utf-8from _ _ future__ import unicode_literalsfrom pyecharts import Barfrom pyecharts import Pageimport randompage = Page () # dataZoom effect, 'slider' type attr = ["{} days" .format (I) for i in range (30)] v1 = [random.randint (1,30) for _ in range (30)] bar = Bar ("Bar-datazoom-slider example") bar.add (", attr, v1, is_label_show=True, is_datazoom_show=True,xaxis_rotate=30, yaxis_rotate=30) page.add (bar) # dataZoom effect 'inside' type attr = ["{} days" .format (I) for i in range (30)] v1 = [random.randint (1,30) for _ in range (30)] bar2 = Bar ("Bar-datazoom-inside example") bar2.add (", attr, v1, is_datazoom_show=True, datazoom_type=" inside ", datazoom_range= [1,50],) page.add (bar2) # dataZoom effect 'both' type attr = ["{} days" .format (I) for i in range (30)] v1 = [random.randint (1,30) for _ in range (30)] bar3 = Bar ("Bar-datazoom-both example") bar3.add (", attr, v1, is_datazoom_show=True, datazoom_type=" both ", datazoom_range= [1,40] Label_color= ["# 749f83"]) page.add (bar3) days = ["{} days" .format (I) for i in range (30)] days_v1 = [random.randint (1,30) for _ in range (30)] bar4 = Bar ("Bar-datazoom-xaxis/yaxis example") bar4.add ("", days, days_v1, # defaults to X axis Horizontal is_datazoom_show=True, datazoom_type= "slider", datazoom_range= [1,50], # add additional dataZoom control bar Vertical is_datazoom_extra_show=True, datazoom_extra_type= "slider", datazoom_extra_range= [1,50], is_toolbox_show=False,) page.add (bar4) page.render (ritual C:\ Users\ ASUS\ Desktop\ restart\ Python draw with pyecharts\ histogram 1.html') above are all the contents of this article "how to draw a histogram in Python". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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