In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to choose Python data Visualization tool". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to choose Python data Visualization tool.
Indicator description
In order to clearly understand the similarities and differences of these Python for visualization in drawing, this article will use the same set of data to make a series of bar charts to compare, mainly through the following indicators to evaluate:
Data description
The data used in this article is faker data in Pyecharts.
From pyecharts.faker import Faker x = Faker.choose () y1 = Faker.values () y2 = Faker.values ()
X is a list of brand names, and y1/y2 is a list of meaningless data of the same length. Let's use different libraries to visualize this set of data!
Pyecharts
Echarts is an open source data visualization by Baidu. With its good interaction and exquisite chart design, it has been recognized by many developers. Python is an expressive language, which is very suitable for data processing. When data analysis meets data visualization, pyecharts is born, supporting 30 + charts. To make a bar chart in pyecharts, you need to import related libraries first.
From pyecharts import options as opts from pyecharts.charts import Bar
Next, the drawing does not make any adjustments, first create a Bar instance, then add x-axis y-axis data, note that only the list format data is received, and finally add the title and set it to display directly in notebook. Generally speaking, it is still in line with the normal mapping logic, and the overall amount of code is not much.
C = (Bar () .add _ xaxis (x) .add _ yaxis ("merchant A", y1) .add _ yaxis ("merchant B", y2) .set _ global_opts (title_opts=opts.TitleOpts (title= "Pyecharts- histogram", subtitle= "")) .render_notebook ()
The two series of bar charts generated by default are as follows:
As you can see, the picture supports interactive display and click, and the default generated style is also more beautiful, and Pyecharts has detailed Chinese documents and demo, and there are many discussions about Pyecharts online, so readers who are new to it can get started relatively quickly. Of course, if you are not satisfied with the default style, you can make some adjustments. Because the document is very complete, the code is not difficult to modify. For example, you can modify the theme and set some markup lines, DataZoom, add widgets, and so on.
Generally speaking, because Pyecharts is based on Echarts, the generated chart is more beautiful, and the official Chinese documents explain the relevant settings in great detail, and there is a lot of discussion about Pyecharts, so if you have related questions in the process of use, it is also easy to find the answer through retrieval, but unfortunately, it does not support the use of series data in pandas, which needs to be converted to list before you can use it. However, the whole is still a visualization library that I am very satisfied with. Subjective score: 85
Matplotlib
Matplotlib should be the most widely used Python visualization tool, supporting many kinds of graphics. To make pictures with the same effect using Matplotlib, you need to import related libraries first, and do not support native Chinese, so you have to set up a Chinese display.
Import matplotlib.pyplot as plt import numpy as np plt.rcParams ['font.sans-serif'] = [' SimHei']
Then there is drawing, but compared with pyecharts, which mostly adds data and configuration to the written code, matplotlib mostly requires us to write our own code, so the amount of code may be a little more.
Width = 0.35x1 = np.arange (len (x)) fig, ax = plt.subplots () rects1 = ax.bar (x1-width/2, y1, width, label=' merchant A') rects2 = ax.bar (x1 + width/2, y2, width, label=' merchant B') ax.set_title ('Matplotlib- histogram') ax.set_xticks (x1) ax.set_xticklabels (x) ax.legend () plt.show ()
The final default image is as follows
The default color matching is not very good-looking but not very ugly, looks a little more academic, but does not support operations such as interactive click viewing, although the amount of code is a little more, but because of the popularity of Matplotlib, there is much more information about matplotlib than Pyecharts, so the process of writing code and adjusting code is not complicated, with an overall subjective score of 77.
Plotly
Plotly is also a very powerful Python visualization library. Plotly has built-in complete interactive capabilities and editing tools, supports both online and offline modes, and provides a stable API to facilitate the integration of existing applications. It can display data charts in web browsers or store local copies. However, due to the lack of official Chinese documents, the online tutorials on Plotly are limited to some official demo, and there is not much information on some detailed parameter settings. First of all, import the relevant library and set up the notebook display.
Import plotly import plotly.offline as py import plotly.graph_objs as go plotly.offline.init_notebook_mode (connected=True)
Next is the drawing code, first of all to deal with the data, the rest of the basic configuration is actually similar to Pyecharts
Trace0 = go.Bar (x = x, y = y1, name = 'merchant Aids,) trace1 = go.Bar (x = x, y = y2, name =' merchant branching,) data = [trace0,trace1] layout = go.Layout (title= {'text': "Plotly- histogram",' ybicycle V0.9, 'xcircle 0.5 name) 'xanchor':' center', 'yanchor':' top'}) fig = go.Figure (data=data, layout=layout) py.iplot (fig)
The image generated by the default style is not ugly as above, and you can see that it supports interactive operation and adds toolbox widgets by default, which can be viewed more easily and supports more than 30 kinds of graphics. generally speaking, it is still an excellent visualization tool, but if you really want to use it skillfully, it may take a little time to find relevant information, because there is not much information about Plotly on the Internet. Most of them are simple tutorials for basic use. If you want to find some detailed operations, for example, in order to find a way to center the title, Baidu uses Google to find similar problems and settings in a foreign forum. Subjective score: 76 points
Bokeh
Bokeh is an interactive visual Python library dedicated to the rendering capabilities of Web browsers. This is the core difference between Bokeh and other visualization libraries. It can make simple and beautiful interactive visualization effects like D3.js, but it is less difficult to use than D3.js. The first thing is to import related libraries.
From bokeh.transform import dodge import pandas as pd from bokeh.core.properties import value import numpy as np import matplotlib.pyplot as plt% matplotlib inline from bokeh.io import output_notebook output_notebook () # Import notebook drawing module from bokeh.plotting import figure,show from bokeh.models import ColumnDataSource# import chart drawing, icon display module # import ColumnDataSource module # import dodge, value module
There are many more dependencies than the above three, and Bokeh has its own data structure ColumnDataSource, so you have to transform the data first, then create the canvas, add data and set up
Df = pd.DataFrame ({'Merchant B':y2 B':y2}, index = x _) _ x = [' Merchant Amalle 'Merchant B'] # Series name data = {' index':x_} for i in _ x: data [I] = DF [I] .tolist () # generate data The data format is dict source= ColumnDataSource (data=data) # to convert the data into ColumnDataSource objects p = figure (x-boken- histogram, y-range = (0150), plot_height=350, title= "boken- histogram", tools= "crosshair,pan,wheel_zoom,box_zoom,reset,box_select,lasso_select") p.vbar (x=dodge ('index',-0.1, range=p.x_range), top=' merchants, width=0.2, source=source,color= "# 718dbf" Legend=value ("Merchant A") p.vbar (x=dodge ('index', 0.1, range=p.x_range), top=' merchant breadth, width=0.2, source=source,color= "# e84d60", legend=value ("Merchant B")) # dodge (field_name, value, range=None) → into a grouped object Value sets show (p) for the position of the element (with width setting) p.xgrid.grid_line_color = None p.legend.location = "top_left" p.legend.orientation = "horizontal" # other parameters
As you can see, the diagram made by Bokeh also supports interaction, and things like styles look more comfortable, but the above picture has been adjusted because the two series are not distinguished by default.
A very obvious feature of Bokeh is that the amount of code is much more than the above three tools, mostly in data processing, and like Plotly, there are not many Chinese materials related to bokeh, and most of them are basically used in the introduction. Although the official map can make a lot of more beautiful pictures than pyecharts, it will take some time to find the relevant parameters, with a subjective score of 71.
Seaborn
As you can see from the title given on the official website of seaborn, seaborn is designed for statistical charts. It is a graphic visualization library based on matplotlib, that is, it is encapsulated by more advanced API on the basis of matplotlib, which makes it easier to make drawings. In most cases, using seaborn can make very attractive maps, while using matplotlib can make more distinctive maps, or our data. To make use of Seaborn, you first need to import related libraries. Since it is based on Matplotlib, you still need to set up Chinese.
Import seaborn as sns import matplotlib.pyplot as plt plt.rcParams ['font.sans-serif'] = [' SimHei']
Then we can generate the picture we want with only one line of code, and the default color matching does not look very ugly.
Thank you for reading, the above is the content of "how to choose Python data Visualization tool". After the study of this article, I believe you have a deeper understanding of how to choose Python data Visualization tool, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.