In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the visualization libraries of Python". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what are the visualization libraries of Python.
Matplotlib, Seaborn, and Pandas:
I'll combine them for several reasons, first of all, Seaborn and Pandas drawings are built on Matplotlib-when you use Seaborn or df.plot () in panda, you're actually using code written by Matplotlib. Therefore, the beauty generated by each method is similar, and the method of customizing images will use a very similar syntax.
When I think of these visualization tools, I think of exploratory data analysis. These packages are great for looking at your data for the first time, but not so good when it comes to presentation. Matplotlib also has a set of style choices that mimic other popular aesthetics, such as ggplot2 and xkcd. Here are some examples of diagrams made using Matplotlib and its close relatives:
When dealing with basketball salary data, I want to find the team with the highest median salary data. To illustrate this point, I color-coded a bar chart. The following is the salary of each team to show which team the players should go to in order to join the well-paid team.
Import seaborn as snsimport matplotlib.pyplot as pltcolor_order = ['xkcd:cerulean',' xkcd:ocean', 'xkcd:black','xkcd:royal purple',' xkcd:royal purple', 'xkcd:navy blue','xkcd: powder blue','xkcd: light maroon',' xkcd:lightish blue','xkcd:navy'] sns.barplot (x=top10.Team, y=top10.Salary Palette=color_order) .set_title ('Teams with Highest Median Salary') plt.ticklabel_format (style='sci', axis='y', scilimits= (0jin0))
Next is the QmurQ diagram of the regression experiment residual. The main purpose of this visualization is to show that we can display a more complete picture with very little code.
Import matplotlib.pyplot as pltimport scipy.stats as stats#model2 is a regression modellog_resid = model2.predict (X_test)-y_teststats.probplot (log_resid, dist= "norm", plot=plt) plt.title ("Normal Qmurq plot") plt.show ()
In the end, Matplotlib and its associated components are very efficient, but in terms of demonstration, they are usually not the final product.
Ggplot (2)
Ggplot is the most popular R visualization software package. Isn't this a Python package review? You might ask. Developers have implemented ggplot2 in Python, copying everything from aesthetics to grammar. From all the materials I've seen, it looks and feels a lot like ggplot2, but it has the added benefit of relying on the pandas Python package, which has recently been deprecated in some ways, causing the Python version of ggplot to become irrelevant. If you want to use a real ggplot in R (it has all the same look, feel, and syntax, no dependencies), I'll discuss some of its extra features here! That is, if you do have to use ggplot in Python, you must install pandas version 0.19.2, but I would like to remind you not to downgrade your pandas so that you can use a poor drawing package.
What makes ggplot2 (and, I guess, Python's ggplot) change the rules of the game is that they use "graphic syntax" to construct graphics. The basic premise is that you can instantiate your picture and then add different functions, that is, titles, axes, data points, and trend lines are added separately, with their own aesthetic attributes. Here are some simple examples of ggplot code. First, we instantiate the graph with ggplot, set up aesthetics and data, and then add points, themes, and axis / title tags.
# All Salariesggplot (data=df, aes (x=season_start, y=salary, colour=team)) + geom_point () + theme (legend.position= "none") + labs (title = 'Salary Over Time', xylene yearing, y='Salary ($)')
Bokeh
Bokeh is beautiful. Conceptually similar to ggplot, it uses graphic syntax to construct graphics. Bokeh has an easy-to-use interface to make very professional graphics and dashboards.
Import pandas as pdfrom bokeh.plotting import figurefrom bokeh.io import show# is_masc is an one-hot encoded dataframe of responses to the question:# "Do you identify as masculine?" # Dataframe Prepcounts = is_masc.sum () resps = is_masc.columns#Bokehp2 = figure (x=resps, top=counts) p2.vbar (x=resps, top=counts) Width=0.6, fill_color='red', line_color='black') show (p2) # Pandascounts.plot (kind='bar')
The bar chart above shows the answers of 538 people in a recent survey to the question "do you think you are a man?" The Bokeh code in lines 9-14 creates an elegant, professional response count histogram with reasonable font size, y tags, and formatting. Most of the code I write is used to mark axes and titles, and to add colors and borders to bar charts. When making beautiful, decent graphics, I am very inclined to Bokeh-a lot of aesthetic work has been done for us!
The blue picture above is a line of code on line 17 of the key point above. The two histograms have the same value, but for different purposes. In an exploratory setup, it's much more convenient to write a line with pandas to view the data, but Bokeh's aesthetics is excellent. All the conveniences provided by Bokeh can be customized in Matplotlib, including the angle of the x-axis label, background line, y-axis extension, font size / italic / bold, and so on. The following figure shows some random trends, using more custom legends and different line types and colors:
Finally, Bokeh is also a good tool for making interactive dashboards.
Plotly
Plotly is very powerful, but the numbers you set up and create take a lot of time and are not intuitive. After spending most of the morning working hard, I went to lunch and saw almost nothing. I created a bar chart without axis labels and a "scatter chart" in which I could not delete the lines. Some noteworthy shortcomings are:
It requires an API key and registration, not just a pip to install it
The data / layout objects drawn are unique pictures and are not intuitive.
The picture layout doesn't work for me (40 lines of code with nothing!)
However, for the disadvantages of all settings, there are advantages and workarounds:
You can edit pictures in the Plotly website and Python environment
There is a lot of support for interactive graphics / dashboards
Plotly works with Mapbox to customize maps
Has amazing overall potential.
If I just use some code to express my dissatisfaction, without showing some code and what I can do, as well as the work done by those who are more capable of using this package, it is unfair to me:
# plot 1-barplot# * * note**-the layout lines do nothing and trip no errorsdata = [go.Bar (x=team_ave_df.team, y=team_ave_df.turnovers_per_mp)] layout = go.Layout (title=go.layout.Title (text='Turnovers per Minute by Team', xref='paper', x = 0) Xaxis=go.layout.XAxis (title = go.layout.xaxis.Title (text='Team', font=dict (family='Courier New, monospace', size=18, color='#7f7f7f')) Yaxis=go.layout.YAxis title = go.layout.yaxis.Title (text='Average Turnovers/Minute', font=dict (family='Courier New, monospace', size=18, color='#7f7f7f'), autosize=True Hovermode='closest') py.iplot (figure_or_data=data, layout=layout, filename='jupyter-plot', sharing='public', fileopt='overwrite') # plot 2-attempt ata scatterplotdata = [go.Scatter (x=player_year.minutes_played, y=player_year.salary, marker=go.scatter.Marker (color='red', size=3))] layout= go.Layout (title= "test", xaxis=dict (title='why'), yaxis=dict (title='plotly')) py.iplot (figure_or_data=data, layout=layout Filename='jupyter-plot2', sharing='public')
Overall, the out-of-the-box look looks good, but repeated attempts to fix axis tags and copy the document verbatim haven't changed anything. However, as I promised before, here are some pictures that show its potential and why it may be worth spending more than a few hours:
Pygal
Pygal is a little-known drawing package that, like other popular packages, uses the syntax of a graphics framework to construct images. Because the picture object is very simple, it is a relatively simple package. Using Pygal is very simple:
Instantiate your picture
Formatting using the properties of a drawing object
Use figure. The Add () symbol adds data to the drawing
The main problem I encountered in Pygal was how to render graphics. I had to use their render_to_file option, and then open the file in a web browser to see what I built. It is ultimately worth it because these numbers are interactive and have a pleasant and easy-to-customize aesthetic. Overall, the package looks good, but there are some file creation / rendering quirks that limit its appeal.
Networkx
Networkx is a good solution for analyzing and visualizing graphics, although it is based on matplotlib. Graphics and networking are not my areas of expertise, but Networkx allows you to graphically represent connected networks quickly and easily. Here are several different representations of a simple diagram I built, as well as some code downloaded from Stanford SNAP to start drawing a small Facebook network.
The code I use to color each node number (1-10) is as follows:
Options = {'node_color': range (len (G)),' node_size': 300, 'width': 1,' with_labels': False, 'cmap': plt.cm.coolwarm} nx.draw (G, * * options)
Thank you for reading, the above is the content of "what is the visualization library of Python". After the study of this article, I believe you have a deeper understanding of what the visualization library of Python has, 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.