python数据可视化

import matplotlib.pyplot as plt
import numpy as np

x=np.arange(0,1,0.05)
print(x)
[0.   0.05 0.1  0.15 0.2  0.25 0.3  0.35 0.4  0.45 0.5  0.55 0.6  0.65
 0.7  0.75 0.8  0.85 0.9  0.95]
#y=sin(2*pi*x)
y=np.sin(2*np.pi*x)
print(y)
[ 0.00000000e+00  3.09016994e-01  5.87785252e-01  8.09016994e-01
  9.51056516e-01  1.00000000e+00  9.51056516e-01  8.09016994e-01
  5.87785252e-01  3.09016994e-01  1.22464680e-16 -3.09016994e-01
 -5.87785252e-01 -8.09016994e-01 -9.51056516e-01 -1.00000000e+00
 -9.51056516e-01 -8.09016994e-01 -5.87785252e-01 -3.09016994e-01]
plt.plot(x,y,'b--*',label='sin')
plt.title('My First Plot')
plt.xlabel('x label')
plt.ylabel('y label')
plt.legend(loc='best')
plt.show()

fig,ax=plt.subplots(2,2)
ax[0,1].plot(x,y)
plt.show()

#y2=np.cos(2*pi*x)
y2=np.cos(2*np.pi*x)
print(y2)
[ 1.00000000e+00  9.51056516e-01  8.09016994e-01  5.87785252e-01
  3.09016994e-01  6.12323400e-17 -3.09016994e-01 -5.87785252e-01
 -8.09016994e-01 -9.51056516e-01 -1.00000000e+00 -9.51056516e-01
 -8.09016994e-01 -5.87785252e-01 -3.09016994e-01 -1.83697020e-16
  3.09016994e-01  5.87785252e-01  8.09016994e-01  9.51056516e-01]
fig,ax=plt.subplots()
ax.plot(x,y,'g--*',label='sin')
ax.plot(x,y2,'r--o',label='cos')
ax.set(title='My First Plot')
legend=ax.legend(loc='upper center')
plt.show()

#保存
fig.savefig('myfig.png')
#读取数据
import pandas as pd

df=pd.read_csv('../data/data.csv',index_col='年份')
df.head()
人均GDP(元)	啤酒产量(万千升)	居民消费价格指数(上面=100)
年份			
2000	7857.7	2231.3	100.4
2001	8621.7	2288.9	100.7
2002	9398.1	2402.7	99.2
2003	10542.0	2540.5	101.2
2004	12335.6	2948.6	103.9
x=df.index.values
y=df['人均GDP(元)'].values
from pylab import mpl

mpl.rcParams['font.sans-serif']=['FangSong'] #指定默认字体
fig,ax=plt.subplots()
ax.plot(x,y,'r--*')
ax.set(title='人均GDP走势图',xlabel='年份')
plt.show()

fig,ax=plt.subplots()
ax.pie(y[:5],labels=x[:5])
plt.show()

fig,ax=plt.subplots()
ax.pie(y[:5],labels=x[:5],explode=[0,0.05,0.1,0.15,0.2])
plt.show()

#绘制词云图
with open('classify_model1 - 副本.csv',encoding='utf-8') as file:
    words=file.read()

print(words)
理财
公告
借款
金额
关注
转让
利率
团队
本息
债权
新手
完成
通知
股权
抵押
金融信息
结束
投资人
付息
累计
from wordcloud import WordCloud

wordcloud=WordCloud(font_path='C:/Windows/Fonts/simfang.ttf').generate(words)
image=wordcloud.to_image()
image.show()
wordcloud=WordCloud(font_path='C:/Windows/Fonts/simfang.ttf',
                   background_color='black',width=600,height=300,max_words=50).generate(words)
image=wordcloud.to_image()
image.show()
#绘制指定形状的词云图
from PIL import Image
images=Image.open('heart.png')
maskImages=np.array(images)

wordcloud=WordCloud(font_path='C:/Windows/Fonts/simfang.ttf',
                   background_color='black',
                   width=600,height=300,
                   max_words=50,mask=maskImages).generate(words)
image=wordcloud.to_image()
image.show()
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值