Python for Data Science - Creating standard data graphics
2021-06-11 07:03
标签:exe eric enc rand data- pyplot res obj lib Python for Data Science - Creating standard data graphics 标签:exe eric enc rand data- pyplot res obj lib 原文地址:https://www.cnblogs.com/keepmoving1113/p/14226855.htmlChapter 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
文章链接:http://soscw.com/index.php/essay/93486.html