[PYTHON] Seaborn basics for beginners ③ Scatter plot (jointplot) * With histogram

What is seaborn

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.

Scatter plot (jointplot)

The theme this time is a scatter plot. Use jointplot to create a scatter plot. In the seaborn scatter plot, the histogram is displayed at the same time as the scatter plot. This is also convenient for grasping the data, and it looks like it and is quite good.

Preparation

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 data frame with pandas.

python


dataframe = pd.read_csv('train.csv')

Basic creation

Use .jointplot to create a scatter plot. Basically, the items to be set are the X-axis item, Y-axis item, and the original data. Take an example of a graph that displays Age on the X-axis and Fare on the Y-axis. As shown in the figure, the point is that it has a histogram.

python


sns.jointplot('Age', 'Fare', data=dataframe)

image.png

As you can see by looking it up, there are various options. If you specify 'hex' for kind, the scatter plot will be on the tile and will be fashionable. It is recommended because it looks good. (It is difficult to convey the original data because it is not good enough.)

python


sns.jointplot('Age', 'Fare', data=dataframe, kind = 'hex')

image.png

It's a very simple syntax, but it's recommended for those who aren't familiar with it because it looks like it and gives a feeling of doing it.

Finally

As even beginners 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

Seaborn basics for beginners ③ Scatter plot (jointplot) * With histogram
Pandas basics for beginners ③ Histogram creation with matplotlib
Seaborn basics for beginners ④ pairplot
[For beginners] Script within 10 lines (8. Plot map with folium [2]
3D scatter plot with PyQtGraph
Pandas basics for beginners ① Reading & processing
Pandas basics for beginners ⑧ Digit processing
Seaborn basics for beginners ① Aggregate graph of the number of data (Countplot)
[Must-see for beginners] Basics of Linux
Pandas basics summary link for beginners
INSERT into MySQL with Python [For beginners]
Getting Started with Python for PHPer-Super Basics
WebApi creation with Python (CRUD creation) For beginners
[For beginners] Try web scraping with Python
Scatter plot
Label each point on the seaborn scatter plot
Causal reasoning and causal search with Python (for beginners)
Plot ROC Curve for Binary Classification with Matplotlib
Visualize coronavirus infection status with Plotly [For beginners]
~ Tips for Python beginners from Pythonista with love ① ~
Create 3D scatter plot with SciPy + matplotlib (Python)
Basics of pandas for beginners ② Understanding data overview
[Introduction for beginners] Working with MySQL in Python
(Memorandum) Make a 3D scatter plot with matplodlib