Beautiful graph drawing with python -seaborn makes data analysis and visualization easier Part 2

Graph drawing in Python

The standard for drawing Python charts is "matplotlib", but it has been pointed out that its appearance is a little unfashionable and the notation is complicated. Therefore, in this article, I will discuss how to use "Seaborn", which is a wrapper to realize the functions of Matplotlib more beautifully and more easily.

Please see the link below for details. In this article, we will proceed on the assumption that the data of Seaborn, iris, tip, and titanic in the following article have been imported.

◆ Beautiful graph drawing with python -Use seaborn to improve data analysis and visualization Part 1 http://qiita.com/hik0107/items/3dc541158fceb3156ee0

Distribution plot

Here, I will use tip data. Let's see how the customer's accounting (total_bill) is distributed for each day of the week. Use a method called stripplot.

stripplot.py


sns.stripplot(x="day", y="total_bill", data=tips)

stripplot.png

Even for the same meal, the amount of money for breakfast and dinner seems to be different, so I used the "hue" I used last time. Let's look at Lunch and Dinner separately.

stripplot.py


sns.stripplot(x="day", y="total_bill", data=tips, hue='time')

stripplot2.png

It seems that this shop does not have lunch on Saturdays and Sundays. What is a restaurant in the office district? ..

Boxplot

Use a method called boxplot.

stripplot.py


sns.boxplot(x="size", y="tip", data=tips.sort('size'))

boxplot.png

Here, I changed the color of the palette of the graph. The way to do it is like this

stripplot.py


flatui = ["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71"]

sns.palplot(sns.color_palette(flatui))
sns.set_palette(flatui)

color.png

Please check this out for details. http://stanford.edu/~mwaskom/software/seaborn/tutorial/color_palettes.html

bar graph

Here, I will try using titanic data. A method called boxplot is used to draw the graph.

barplot.py


sns.barplot(x='sex', y='survived', data=titanic, hue='class')

The x-axis is gender and the y-axis is survived, that is, a data string containing 1s and 0s for survivors or dead. In this case, for example, there are many records with gender = male, so the number used for the Y-axis is the average value of each record. Then, an error bar from the average value is added to represent the value of all records.

You may need to be a little careful about this area.

barplot.png

If you want the total value of Survived instead of the average, is it best to aggregate it with Pandas and then graph it? Maybe there are other ways.

barplot2.py


titanic_grpby = titanic.groupby( ['sex', 'class'])
titanic_data_for_graph = titanic_grpby['survived'].aggregate(sum).reset_index()

sns.barplot(x='sex', y='survived', hue= 'class', data=titanic_data_for_graph)

boxplot2.png

Bar graph (count)

Use Count plot if you want the Y-axis value to be the count of the data that corresponds to the X-axis. As with the histogram, you only need to define the x-axis.

By the way, the color of the graph can also be specified with the option called palette.

countplot.py


sns.countplot(x='sex', hue='embarked', data=titanic, palette='Greens_d')

countplot.png

Recommended Posts

Beautiful graph drawing with python -seaborn makes data analysis and visualization easier Part 1
Beautiful graph drawing with python -seaborn makes data analysis and visualization easier Part 2
Easy data visualization with Python seaborn.
Data analysis starting with python (data visualization 1)
Data analysis starting with python (data visualization 2)
[In-Database Python Analysis Tutorial with SQL Server 2017] Step 3: Data Exploration and Visualization
Data analysis with python 2
Easy analysis sharing with re: dash, an open source data visualization tool Part 2 ~ Graph
Easy analysis sharing with re: dash, an open source data visualization tool Part 3 ~ Google Spreadsheets
Easy analysis and sharing with re: dash, an open source data visualization tool Part 1-Installation
Try to get CloudWatch metrics with re: dash python data source
Easy data visualization with Python seaborn.
Data analysis starting with python (data visualization 1)
Data analysis starting with python (data visualization 2)
Python visualization tool for data analysis work
Beautiful graph drawing with python -seaborn makes data analysis and visualization easier Part 1
Beautiful graph drawing with python -seaborn makes data analysis and visualization easier Part 2
Data analysis with Python
Overview and tips of seaborn with statistical data visualization
Easy analysis sharing with re: dash, an open source data visualization tool Part 2 ~ Graph
Get a large amount of Starbucks Twitter data with python and try data analysis Part 1
Easy analysis and sharing with re: dash, an open source data visualization tool Part 1-Installation
Scraping with Python and Beautiful Soup
Python application: data visualization part 1: basic
Data pipeline construction with Python and Luigi
Starbucks Twitter Data Location Visualization and Analysis
Python visualization tool for data analysis work
FM modulation and demodulation with Python Part 3
Process Pubmed .xml data with python [Part 2]
Sensor data acquisition and visualization for plant growth with Intel Edison and Python
Easily graph data in shell and Python
Tweet analysis with Python, Mecab and CaboCha
FM modulation and demodulation with Python Part 2
Recommendation of Altair! Data visualization with Python
Data analysis starting with python (data preprocessing-machine learning)
Graph analysis and visualization on IPython Notebook using Cytoscape / cyREST and py2cytoscape Part 1
Draw a graph with PyQtGraph Part 1-Drawing
[Python] From morphological analysis of CSV data to CSV output and graph display [GiNZA]
Create test data like that with Python (Part 1)
Read Python csv data with Pandas ⇒ Graph with Matplotlib
[Various image analysis with plotly] Dynamic visualization with plotly [python, image]
Implement "Data Visualization Design # 3" with pandas and matplotlib
Data analysis planning collection processing and judgment (Part 1)
Data analysis planning collection processing and judgment (Part 2)
Data analysis python
I created a stacked bar graph with matplotlib in Python and added a data label
Quickly create a Python data analysis dashboard with Streamlit and deploy it to AWS
I tried various things with Python: scraping (Beautiful Soup + Selenium + PhantomJS) and morphological analysis.
Analysis of financial data by pandas and its visualization (2)
Data analysis for improving POG 1 ~ Web scraping with Python ~
Analysis of financial data by pandas and its visualization (1)
[# 2] Make Minecraft with Python. ~ Model drawing and player implementation ~
Data analysis environment construction with Python (IPython notebook + Pandas)
Challenge principal component analysis of text data with Python
Investigate Java and python data exchange with Apache Arrow
Create a decision tree from 0 with Python and understand it (3. Data analysis library Pandas edition)
I tried the same data analysis with kaggle notebook (python) and Power BI at the same time ②
Easy analysis sharing with re: dash, an open source data visualization tool Part 3 ~ Google Spreadsheets
"Measurement Time Series Analysis of Economic and Finance Data" Solving Chapter End Problems with Python
I tried the same data analysis with kaggle notebook (python) and Power BI at the same time ①
[Python Seaborn Graph Library] About User Warning of axes.color_cycle is deprecated and replaced with axes.prop_cycle
[Graph drawing] I tried to write a bar graph of multiple series with matplotlib and seaborn
Python Data Visualization Libraries
Data analysis using Python 0
Data analysis overview python
Graph drawing in python
Voice analysis with python
Data visualization with pandas
Python data analysis template
Drawing with Python Tinker