A library for drawing Python graphs. .. Positioned as a wrapper function (inclusive program) of matplotlib, the most famous libra. In addition to being able to easily draw beautiful-looking graphs, it also has a certain amount of functions such as batch processing. Matplotlib is for detailed specification and drawing, and seaborn is for easy and beautiful.
First, install the seaborn
library with pip. For pip ?, click here ('https://qiita.com/Yanagawa_Yoshihisa/items/35e6f70a8411277282ce').
Import the library. Name seaborn`` sns
and ʻimport`.
python
import seaborn as sns
I will try the sample with Titanic data. If you don't know Titanic, please check "kaggle Titanic". Create a dataframe with pandas.
python
dataframe = pd.read_csv('train.csv')
This is the aggregate visualization of the number of the most basic data. Use Count plot
for this. Basically, the Y axis is the number of cases, so specify only the X axis.
As an example, draw the relationship between Pclass (room grade) and the number of cases. Specify P class
for the X-axis x
and data frame
for the original data data
.
python
sns.countplot(x="Pclass", data=dataframe)
If you specify the Y axis, it will lie down.
python
sns.countplot(y="Pclass", data=dataframe)
If you want to add a series, add hue
. (As an example, add Sex to hue
.)
python
sns.countplot(y="Pclass", data=dataframe, hue='Sex')
You can also change the order and color of the axes, so if you are interested, please check it out.
Also, changing the label can be done by modifying matplotlib, which is the original wrapper source, but it is complicated and will be omitted.
With Count plot
, the benefits may not be felt. I think that other distplot`` pairplot
joint plot
etc. will be more beneficial.
As a beginner can understand, we have summarized the necessary knowledge when implementing machine learning with Python as a simple article. The table of contents is here, so I hope you can refer to other articles as well.
Recommended Posts