In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you Python programming using matplotlib to pick diamonds seaborn drawing example analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
Seaborn is a supplement to matplotlib, provides a series of good-looking figure, and integrates a variety of online data sets, which can be called through sns.load_dataset () for learning. If the network is unstable, it can be downloaded locally, and then set cache to True when calling.
Scatter_plot
The official example is good, drawing diamond data in the diamonds dataset. The diamonds contains a total of ten items of data, namely weight / carat, cutting level, color, transparency, depth, table, price, and dimensions in x, y, z directions.
We can first see if there is a certain correlation between the dimensions in the x and y directions.
Import seaborn as snsimport matplotlib.pyplot as plt# local load dataset dia = sns.load_dataset ("diamonds", data_home= "seaborn-data", cache=True) # sns.scatterplot (x=dia ['x'], y=dia ['y'], size=5) plt.show () # is not repeated after the above lines of code, which is used to display the picture.
Where x-ray represents x-axis and y-axis data respectively, it can be seen that the general diamond is relatively regular.
The official gallery draws the following images
The Abscissa of this picture is the weight (carat) and the ordinate is the price. We find that most diamond traders have obsessive-compulsive disorder, because there are more diamonds in the whole ten whole five of 2.0 carat, 1.5 carat and 1.0 carat than the surrounding weight diamonds.
F, ax = plt.subplots (figsize= (6.5,6.5) sns.set_theme () sns.despine (f, left=True, bottom=True) clarity = ["I1", "SI2", "SI1", "VS2", "VS1", "VVS2", "VVS1", "IF"] # order of color depth sns.scatterplot (x = "carat", y = "price", # declare the values of the x and y axes hue= "clarity", size= "depth" # clarity and depth control color and size palette= "ch:rot=-.2,d=.3_r", # color palette style_order=clarity,sizes= (1mai 10), # order and size range of color identification linewidth=0,data=dia, ax=ax) plt.show ()
First, set_theme is used to set the theme, where style can enter a string or dictionary to adjust the theme style.
Second, palette stands for color mapping, which means when its input value is a string
Range of abbreviations
Starts [0BI 3] gradient starting point color rotr
It is used to adjust the hue gammag not less than 0 less than 1 to improve the dark part, and when greater than 1, to enhance the intensity of the darkest part of the highlight hueh [0Magne1] Saturation of the colors.darkd [0Magne1] the intensity of the brightest color of lightl [0Magne1]
Sizes is used to resize points, and when setting size, the values in size are mapped to ssizes to draw.
We notice that one of the diamond attributes is the cutting level, so let's draw the relationship between the cutting level and the price.
Fig, ax = plt.subplots (figsize= (6.5,6.5) sns.set_theme () sns.despine (fig, left=True, bottom=True) sns.scatterplot (data = dia, x = "carat", y = "price", hue='cut', linewidth=0) plt.show ()
Sure enough, after the gradient color is removed, the appearance is crazy, but at the same time, it can be found that this very good is obviously not the best cutting grade. after all, among the 3.0-carat diamonds, there is a very good diamond with the lowest price. GIA has a diamond rating from Excellent,Very Good,Good,Fair to the worst Poor, and maybe ideal represents Excellent in this dataset.
Lmplot
If you want to more accurately observe the impact of cut on diamond prices, you can use lmplot to draw a trend line based on the scatter chart.
Sns.lmplot (data=dia, x = "carat", y = "price", hue='cut',markers ='.') plt.show ()
In this way, we can see that ideal's diamond is the best.
Jointplot
The above pictures are the issues that consumers are most concerned about-price, size, transparency and so on. But merchants may be most concerned about the relationship between price, weight and sales volume, which involves a problem of distribution. And seaborn provides a very good bivariate diagram-jointplot, the effect is as follows
It can be seen that the cheap diamonds are more popular, the codes are respectively
# left code sns.jointplot (data=dia, x = "carat", y = "price", xlim= (0Magne3), ylim= (0jing17500), ratio=10,kind='hex',color= "# 4CB391") # right code sns.jointplot (data=dia, x = "carat", y = "price", hue='cut', xlim= (0Magne3), ylim= (0j17500), ratio=10,marker='.')
Kind is used to change the style of the image, and sns provides six styles: "scatter", "kde", "hist", "hex", "reg" and "resid".
The above is all the contents of this article entitled "sample Analysis of Python programming using matplotlib to pick Diamond seaborn drawing". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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.
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.