Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Python programming matplotlib to draw Diamond seaborn Violin and Box Diagram

Shulou Source: shulou.com Published: 2022-06-01 08:02:28 09月30日 Update

This article mainly introduces how to use Python programming matplotlib drawing pick diamond seaborn violin and box diagram, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

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.

Among them, the diamonds data set contains diamond data, a total of ten items, namely [weight / carat] carat, cutting level cut, color color, transparency clarity, depth depth, table, price price and dimensions in x, y, z directions.

The first step in drawing is to import packages and data.

Import seaborn as snsimport matplotlib.pyplot as plt# locally loaded dataset dia = sns.load_dataset ("diamonds", data_home= "seaborn-data", cache=True) # the box diagram is not repeated after the above lines of code

Now we want to know the price range of the five cutting methods: Premium, Fair, Very Good, Good and Ideal, so the most direct idea is to make a box line diagram, which is similar to the K-line diagram.

In this diagram, the box and line describe five statistics: the minimum abnormal value, the first quartile (25%), the median, the third quartile (75%), and the non-abnormal maximum. The points above the maximum are outliers. It can be seen that diamonds worth more than $15000 are different.

> sns.boxplot (x = "cut", y = "price", data=dia,color='lightblue',fliersize=0.25) > plt.show ()

Where fliersize represents the size of the exception value.

Enhanced box diagram

Although the box chart can describe certain distribution characteristics, it is not enough. After all, there are only five statistics.

An enhanced version of the box chart is available in sns: boxenplot

In this diagram, the price range is divided, and in each price range, the wider the box, the more samples.

Sns.boxenplot (x = "cut", y = "price", data=dia, palette= "ch:rot=-.5,d=.3_r") plt.show () violin

If you want to be more detailed, you have to use a violin picture.

Sns.violinplot (x = "cut", y = "price", data=dia) sns.despine (left=True)

From this point of view, the price range of the best cut diamonds is about 1000, which is outrageous, but it is also very real.

Thank you for reading this article carefully. I hope the article "how to use Python programming matplotlib drawing to pick Diamond seaborn Violin and Box Diagram" shared by the editor will be helpful to everyone. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Diagram diamond price data violin interval article drawing programming maximum digit size maximum graph learning statistics minimum outrageous meticulous not enough Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Microsoft Docker Apple MySQL