Python for Data Science - Creating standard data graphics

2021-06-11 07:03

阅读:654

标签:exe   eric   enc   rand   data-   pyplot   res   obj   lib   

Chapter 4 - Practical Data Visualization

Segment 1 - Creating standard data graphics

import numpy as np
from numpy.random import randn
import pandas as pd
from pandas import Series, DataFrame

import matplotlib.pyplot as plt
from matplotlib import rcParams

Creating a line chart from a list object

Plotting a line chart in matplotlib

x = range(1,10)
y = [1,2,3,4,0,4,3,2,1]

plt.plot(x,y)
[]

技术图片

Plotting a line chart from a Pandas object

address = ‘~/Data/mtcars.csv‘

cars = pd.read_csv(address)
cars.columns = [‘car_names‘,‘mpg‘,‘cyl‘,‘disp‘, ‘hp‘, ‘drat‘, ‘wt‘, ‘qsec‘, ‘vs‘, ‘am‘, ‘gear‘, ‘carb‘]

mpg = cars[‘mpg‘]
mpg.plot()

技术图片

df = cars[[‘cyl‘,‘wt‘,‘mpg‘]]
df.plot()

技术图片

Creating bar charts

Creating a bar chart from a list

plt.bar(x,y)

技术图片

Creating bar charts from Pandas objects

mpg.plot(kind="bar")

技术图片

mpg.plot(kind="barh")

技术图片

Creating a pie chart

x = [1,2,3,4,0.5]
plt.pie(x)
plt.show()

技术图片

Saving a plot

plt.pie(x)
plt.savefig(‘plt_chart.png‘)
plt.show()

技术图片

%pwd
‘/home/ericwei/Ex_Files_Python_Data_Science_EssT_Pt_1/Exercise Files/04_01_begin‘

Python for Data Science - Creating standard data graphics

标签:exe   eric   enc   rand   data-   pyplot   res   obj   lib   

原文地址:https://www.cnblogs.com/keepmoving1113/p/14226855.html


评论


亲,登录后才可以留言!