其他分享
首页 > 其他分享> > gdp+weather+air.html

gdp+weather+air.html

作者:互联网

3-2-1

import pandas as pd
df=pd.read_csv(r"E:\junior\datasource\gdp\output1\part-r-00000",sep='\t',header=None)
df.columns=['大洲名称','总GDP数']
df.head()

import matplotlib
from matplotlib import pyplot as plt
matplotlib.rcParams['font.family']='SimHei'
matplotlib.rcParams['font.sans-serif']=['SimHei']
# plt.figure(figsize=(10,6))
x=df['大洲名称']
y=df['总GDP数']
plt.bar(x,y,width=0.5,color='g',label='GDP')
plt.xlabel('大洲名称')
plt.ylabel('总GDP数(万亿)')
plt.title('各大洲总GDP图')
plt.legend(fontsize=12)
plt.show()

3-2-2

import pandas as pd
df=pd.read_csv(r"E:\junior\datasource\gdp\output2\part-r-00000",sep='\t',header=None)
df.columns=['年份','中国GDP数']
df.head()

df=df['年份']
df

# plt.figure(figsize=(10,10))
import numpy as np
import matplotlib
from matplotlib import pyplot as plt
matplotlib.rcParams['font.family']='SimHei'
matplotlib.rcParams['font.sans-serif']=['SimHei']
x=df['年份'].astype(dtype=np.str_)
plt.plot(x,df['中国GDP数'],label='中国GDP数(万亿)',color='r')
#设置图例,标题
plt.legend()
# plt.xticks(x,rotation=30)
plt.title("中国 GDP 数走势图")
plt.xlabel("年份")
plt.ylabel("中国GDP数")
# plt.xticks(data1['年份'],rotation=30,fontsize=11)
#显示图形
plt.show()

3-2-3

import pandas as pd
df=pd.read_csv(r"E:\junior\datasource\weather\output1\part-r-00000",sep='\t',header=None)
df.columns=['年份','平均气温']
df.head()

import matplotlib
from matplotlib import pyplot as plt
plt.figure(figsize=(9,6))
matplotlib.rcParams['font.family']='SimHei'
matplotlib.rcParams['font.sans-serif']=['SimHei']
plt.plot(df['年份'],df['平均气温'],label='平均气温')
#设置图例,标题
plt.legend()
plt.title("2018 年长沙各月份平均气温趋势图")
plt.xlabel("年份")
plt.ylabel("平均气温")
labels=["2018/01","2018/02","2018/03","2018/04","2018/05","2018/06","2018/07","2018/08","2018/09","2018/10","2018/11","2018/12"]
plt.xticks(df['年份'],labels)
#显示图形
plt.show()

3-2-4

import pandas as pd
df=pd.read_csv(r"E:\junior\datasource\weather\output2\part-r-00000",sep='\t',header=None)
df.columns=['天气情况','天数']
df.head()

import matplotlib
import matplotlib.pyplot as plt
matplotlib.rcParams['font.family']='SimHei'
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
plt.figure(figsize=(10,8))
plt.pie(df['天数'],labels=df['天气情况'],autopct='%.2f%%')
plt.title("2018 年长沙全年各种类型天气占比数量图")
plt.legend(loc='upper left',bbox_to_anchor=(-0.3,1.0)) 
plt.show()

3-2-5

import pandas as pd
df=pd.read_csv(r"E:\junior\datasource\weather\output3\part-00000",header=None,delimiter=',')
df.columns=['天气情况','天数']
df.head()

df['天气情况']=df['天气情况'].map(lambda x: x.split('(',1)).str[1]
df['天数']=df['天数'].map(lambda x: x.split(')',1)).str[0]
df['天数'].astype(dtype=int)
df.head()

import matplotlib
import matplotlib.pyplot as plt
matplotlib.rcParams['font.family']='SimHei'
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
plt.figure(figsize=(10,8))
plt.pie(df['天数'],labels=df['天气情况'],autopct='%.2f%%')
plt.title("2018 年长沙全年各种类型天气占比数量图")
plt.legend(loc='upper left',bbox_to_anchor=(-0.3,1.0)) 
plt.show()

3-2-6

import pandas as pd
df=pd.read_csv(r"E:\junior\datasource\air\output1\part-r-00000",sep='\t',header=None)
df.columns=['质量等级','天数']
df.head()

import matplotlib
import matplotlib.pyplot as plt
matplotlib.rcParams['font.family']='SimHei'
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
plt.figure(figsize=(10,8))
plt.pie(df['天数'],labels=df['质量等级'],autopct='%.2f%%')
plt.title("2019 年北京全年空气质量等级分布图")
plt.legend(loc='upper left',bbox_to_anchor=(-0.3,1.0)) 
plt.show()

 

标签:gdp,plt,df,html,matplotlib,weather,2018,import,font
来源: https://www.cnblogs.com/modikasi/p/16688982.html