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 make a large data screen with PywebIO module in python

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

Share

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

This article mainly introduces how to use the PywebIO module in python to make a large data screen related knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe that after reading this article on how to use the PywebIO module in python to make a large data screen article will have a harvest, let's take a look at it.

1. Introduction of PywebIO

The PywebIO module in Python can help developers quickly build Web applications or browser-based GUI applications without HTML and JavaScript. PywebIO can also be used in conjunction with some commonly used visualization modules to create a large visual screen.

Let's first install the modules we need.

Pip install pywebiopip install cutecharts

The cutecharts module mentioned above is a hand-drawn visual artifact in Python. I believe you are no stranger to this. Let's take a look at what it looks like to draw a chart in combination with the PywebIO module.

The code is as follows:

From cutecharts.charts import Barfrom cutecharts.faker import Fakerfrom pywebio import start_serverfrom pywebio.output import put_htmldef bar_base (): chart = Bar ("Bar- basic example", width= "100%") chart.set_options (labels=Faker.choose (), X-ray label = "Ihumm xlabel", yearly label = "Ihumm ylabel") chart.add_series ("series-A") Faker.values () put_html (chart.render_notebook ()) if _ _ name__ = ='_ main__': start_server (bar_base, debug=True, port=8080)

Output:

The logic of the above code is not difficult to understand. First instantiate a histogram Bar () object, then fill in the label corresponding to the X axis and the value of the corresponding Y axis, and finally call the put_html () method in the PywebIO module. We will see a URL.

Enter the URL in the browser and you can see the chart we have drawn. Of course, there is a Page () method in the cutecharts module to connect each chart together to make a large visual screen.

The code is as follows:

Def bar_base (): chart = Bar ("Bar- basic example", width= "100%") chart.set_options (labels=Faker.choose (), x-ray ylabel = "Ihumm xlabel", yearly label = "Ihumm ylabel") chart.add_series ("series-A", Faker.values ()) return chartdef pie_base ()-> Pie: chart = Pie ("title", width= "100%"). Return chartdef radar_base ()-> Radar: chart = Radar ("title", width= "100%") Return chartdef line_base ()-> Line: chart = Line ("title", width= "100%") Return chartdef main (): page = Page () page.add (pie_base (), pie_base (), radar_base (), line_base (), bar_base ()) put_html (page.render_notebook ()) if _ _ name__ = ='_ main__': start_server (main, debug=True, port=8080)

Output:

2. The combination of PywebIO and Pyecharts

When the PywebIO module encounters the Pyecharts module, the logic of the code is basically the same as that of cutecharts, first instantiating the object of a chart, then after adding data and styling the chart, finally calling the put_html () method to render the final result in the browser

# `chart` is an example of your chart pywebio.output.put_html (chart.render_notebook ())

In this case, we call the composite component in Pyecharts to render the completed chart, as follows:

Def bar_plots (): bar = (Bar () .add _ xaxis (Faker.choose ()) .add _ yaxis ("merchant A", Faker.values ()) .add _ yaxis ("merchant B") Faker.values () .set _ global_opts (title_opts=opts.TitleOpts (title= "Grid-Bar")) return bardef line_plots (): line = (Line () .add _ xaxis (Faker.choose ()) .add _ yaxis ("merchant A", Faker.values ()) .add _ yaxis ("merchant B") Faker.values () .set _ global_opts (title_opts=opts.TitleOpts (title= "Grid-Line", pos_top= "48%"), legend_opts=opts.LegendOpts (pos_top= "48%")) return linedef main (): C = (Grid () .add (bar_plots ()) Grid_opts=opts.GridOpts (pos_bottom= "60%") .add (line_plots (), grid_opts=opts.GridOpts (pos_top= "60%")) c.width = "100%" put_html (c.render_notebook ()) if _ _ name__ = ='_ main__': start_server (main, debug=True, port=8080)

Output:

Third, the combination of PywebIO and Bokeh

The combination of PywebIO and Bokeh will be slightly different from the above in terms of syntax, and the specific differences are as follows:

From bokeh.io import output_notebookfrom bokeh.io import showoutput_notebook (notebook_type='pywebio') fig = figure (...)... show (fig)

For example, let's draw a simple histogram with the following code:

Def bar_plots (): output_notebook (notebook_type='pywebio') fruits = ['Apples',' Pears', 'Nectarines',' Plums', 'Grapes',' Strawberries'] counts = [5,3,4,2,4,6] p = figure (x_range=fruits, plot_height=350, title= "Fruit Counts", toolbar_location=None, tools= "") p.vbar (x=fruits, top=counts Width=0.9) p.xgrid.grid_line_color = None p.y_range.start = 0 show (p) if _ _ name__ = "_ _ main__": start_server (bar_plots, debug=True, port=8080)

Output:

4. Browser-based GUI application

In addition to combining the Pywebio module with common visualization modules for drawing various charts, we can also use it to build a browsing-based graphical interface. Let's first do the simplest application, the code is as follows:

From pywebio.input import * from pywebio.output import * data = input_group ("user data", [input ("may I ask your name is:", name= "name", type=TEXT), input ("enter your age", name= "age", type=NUMBER), radio ("which continent", name= "continent", options= ["Africa") "Asia", "Australia", "Europe", "North America", "South America",], checkbox (user Privacy regulations, name= "agreement", options= ["consent"]),] ) put_text ("form output:") put_table ([["name", data ["name"]], ["Age", data ["age"]], ["location", data ["continent"]], [regulations, data ["agreement"]],])

Output:

Some of the function methods are explained as follows:

Input (): input of text content

Radio (): represents the radio box

Checkbox (): represents a multi-box

Input_group (): represents the input group

Put_table (): represents the output group

Put_text (): represents the output text

This is the end of the article on "how to use the PywebIO module in python to make a big data screen". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to use the PywebIO module in python to make a big data screen". If you want to learn more knowledge, you are 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