In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what are the skills of the drawing tool Seaborn in Python". In the daily operation, I believe that many people have doubts about the skills of the drawing tool Seaborn in Python. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "what are the skills of the drawing tool Seaborn in Python?" Next, please follow the editor to study!
Base diagram
The script in this article was tested in python3.8.3.
Let's use Seaborn's built-in penguins dataset as sample data:
# Import package import matplotlib.pyplot as pltimport seaborn as sns# Import data df = sns.load_dataset ('penguins') .rename (columns= {' sex': 'gender'}) df
We will use the default chart settings to build a standard scatter chart to use as a baseline:
# figure sns.scatterplot (data=df, alpha=0.7, hue='species', size='gender')
We will see how this diagram changes with each technique.
Sports Acrobatics
As you will see, the first two techniques are used for a single drawing, while the remaining four techniques are used to change the default settings for all charts.
Tip 1: semicolon
Have you noticed that in the previous picture, the text output is directly at the top of the chart? A simple way to suppress this text output is to use; at the end of the drawing.
# figure sns.scatterplot (data=df, alpha=0.7, hue='species', size='gender')
Just add at the end of the code; you can get clearer output.
Skill 2:plt.figure ()
Drawing usually benefits from resizing. If we want to resize, we can do this:
# figure plt.figure (figsize= (9,5)) sns.scatterplot (data=df, alpha=0.7, hue='species', size='gender')
When we resize, the legend moves to the upper left corner. Let's move the legend out of the chart so that it does not accidentally overwrite the data points:
# figure plt.figure (figsize= (9,5)) sns.scatterplot (data=df, xylene bodyweight massages, alpha=0.7, hue='species', size='gender') plt.legend (loc='upper right', bbox_to_anchor= (1.2,1))
If you want to know how to know what word combinations figsize () or bbox_to_anchor () use, you need to try which numbers are best suited for drawing.
Skill 3:sns.set_style ()
If you do not like the default style, this function helps to change the overall style of the drawing. This includes the color and background of the axis. Let's change the style to whitegrid and see how the appearance of the plot changes:
# change the default style sns.set_style ('whitegrid') # figure plt.figure (figsize= (9,5)) sns.scatterplot (data=df, xylene / bodyweight massages, alpha=0.7 / hue='species', size='gender') plt.legend (loc='upper right', bbox_to_anchor= (1.2,1))
Here are some other options to try: "darkgrid", "dark" and "ticks" to find the one you like better.
Skill 4:sns.set_context ()
In the previous figure, the label size looks very small. If you don't like the default settings, we can use sns.set_context () to change the context parameters.
I use this function mainly to control the default font size of the labels in the drawing. By changing the default values, we can save time without having to resize fonts for different elements of a single drawing (such as axis labels, headings, legends). Let's change the context to "talk" and look at the figure:
# default context change sns.set_context ('talk') # figure plt.figure (figsize= (9,5)) sns.scatterplot (data=df, xylene / bodyweight massages, alpha=0.7 / hue='species', size='gender') plt.legend (loc='upper right', bbox_to_anchor= (1.3,1))
It's easier to recognize, isn't it? Another option you can try is "poster", which will increase the default size or more.
Skill 5:sns.set_palette ()
This feature is very convenient if you want to customize the default palette to your favorite color combination. We can use the color mapping in Matplotlib. This is selected from the color library. Let's change the palette to "rainbow" and look at the figure again:
# change the default palette sns.set_palette ('rainbow') # figure plt.figure (figsize= (9,5)) sns.scatterplot (data=df, X-ray billboard massaging, alpha=0.7, hue='species', size='gender') plt.legend (loc='upper right', bbox_to_anchor= (1.3,1))
If you can't find your favorite Matplotlib color mapping, you can manually select colors to create your own unique palette. One way to create your own palette is to pass a list of color names to the function, as shown in the following example.
# change the default palette sns.set_palette (['green',' purple', 'red']) # figure plt.figure (figsize= (9,5)) sns.scatterplot (data=df, X-ray billboard massages, alpha=0.7, hue='species', size='gender') plt.legend (loc='upper right', bbox_to_anchor= (1.3,1))
If the color name doesn't capture what you're looking for, you can use hexadecimal colors to build your own palette to access a wider range of options (more than 16 million colors! ). Here is my favorite resource, you can find a custom color palette in hexadecimal. Let's look at an example:
# change the default color palette sns.set_palette (['# 62C370mm,'# FFD166','# EF476F']) # figure plt.figure (figsize= (9,5)) sns.scatterplot (data=df, x-shaped bodyweight massages, alpha=0.7, hue='species', size='gender') plt.legend (loc='upper right', bbox_to_anchor= (1.3,1) At this point, the study of "what are the skills of the drawing tool Seaborn in Python" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.