This article is participating in “Python Theme Month”

Today I share a data visualization library: bokeh.org/

What is a bokeh? What does it do?

Bokeh is a Python library for data visualization. It provides functions for plot (two-dimensional diagram) and multiple style diagram generation.

This helps developers, and more often data analysts, quickly present data into multiple charts.

The installation

pip install bokeh

Viewing the Installation Effect

bokeh info

I wrote demo1.py here

Here are two dimensions, x (year, 2017 to 2021); Y (Gold fluctuates from 99 to 115.9).

The code is straightforward: the x array is years, and the Y array is a set of imaginary gold prices. Then create an instance of a figure, where p represents a two-dimensional diagram.

Then draw the line P.line on the graph, specifying x, y data, line width, etc.

The renderings are as follows:

Well, if you want to show the price fluctuation of two products, that’s easy.

I’m going to add 14 and 15, so I’m going to add the y2 array on the Y-axis, and I’m going to do it in a different color.

To make things more complicated, here is a scatter plot. You can change the size of the dots and the scale of the wheelbase by setting them.

Look at the code:

It’s very simple and intuitive. Let’s look at the code from the diagram, and it’s divided into three main pieces.

  • Div, spinner: Div is a text prompt, and spinner renders a graphical control number component to pass in the size of the current diagram
  • Ranger_slider: a range slider component with a range of [2010 2020] and a step of 1.
  • P: A plot two-dimensional graphics component

Finally, the three blocks are used to build a layout object, which is displayed as an overall diagram.

Finally, show one saved as HTML:

Here the code is: gitee.com/leixuewei/d… This article will not do too much analysis, the reader can think about it.

Code REPO is continuously updated: gitee.com/leixuewei/d… Here shows the three kinds of use, is focused on the analysis of the mastery of data and charts, more content please click: docs.bokeh.org/en/latest/d…

For the coding experience, copy a more basic Python project: mp.csdn.net/editor/html… , in the experiment article code.

Creation is not easy, hope a key three or a lot of feedback, thanks!

By the way, the school committee also has this can pay attention to long-term reading => lei School committee interesting programming story compilation

Continuous learning and continuous development, I am the Lei School committee! Programming is fun, but the key is to get the technology straight. Welcome to follow, and feel free to like the collection!

The blogger will be updating the data science series for a long time.