🔖 [Data Science] Matplotlib

2018 - 09 - 16
🔖 [Data Science] Matplotlib
0. [Introduction] Python is good for machine learning and data analysis because of its libraries. Matplotlib is the most common plotting library which helps to draw simple diagram from data. By using Numpy and Pandas, data can be imported to Anaconda - Jupyter Notebook. Unlike building application or websites, it is better to use Notebook for data science as the plotting can be presented neatly. So, here are the prerequisites:
1. [Import libraries] First, we have to create a new notebook using Jupyter. Open Anaconda application: Then open a new notebook using Python3, under the same folder as the *csv downloaded. Here is the page that we're going to import the libraries:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
Press Ctrl+Enter (This is the way to run codes in Jupyter). We use %matplotlib inline to automatically show the plotted diagram without repeatedly typing plt.show() Then we can move on to import data.
2. [Import data] Insert a new cell below, and use Pandas to import data frame: Copy the snippet below into the row
df = pd.read_csv('WorldCups.csv')
We could see the first 5 rows of data from previous world cup champions in a table.
3. [Plot figure] After importing the data, we could use it to plot diagrams easily. Let's say we want to see the number of attendances across years:
plt.plot(df['Year'], df['Attendance'])
And we could see a diagram like this: We used plt.figure(figsize=(12,6)) to show a better diagram aspect ratio. plt.plot is a function for plotting, the first argument is X-axis while the second is Y-axis. To plot more complicated diagrams such as data from multi-columns and heatmap, we could use another library named SeaBorn which is more powerful and colourful.


Ктпну, КТП КОМПЛЕКТНЫЕ ТРАНСФОРМАТОРНЫЕ ПОДСТАНЦИИ москва, Производство ктп москва, а также многое другое Вы найдете на нашем специализированном сайте: http://sviloguzov.ru/ - Здесь есть то, что Вам нужно!
April 6, 2019, 5:16 a.m.

New Comment

Please Login to comment