数据可视化常用

2017-10-31  本文已影响0人  Don_Mills_3675

1.折线图:matplotlib.pyplot.plot()

#绘制图形
#设置图形大小、长宽比例
figure=plt.figure(dpi=128,figsize=(12,6))
#设置x轴y轴数据和线条颜色
plt.plot(dates_1,highs_1,c='red')
plt.plot(dates_1,lows_1,c='red')
#设置两条线之间填充色
plt.fill_between(dates_1,highs_1,lows_1,facecolor='red',alpha=0.1)

#图像格式
plt.title('2014年每日最高温度、最低温度、平均温度-死亡谷-锡特卡',fontsize=24)
plt.xlabel('日期',fontsize=16)
#绘制斜的日期标签
figure.autofmt_xdate()
plt.ylabel('温度',fontsize=16)
plt.tick_params(axis='both',which='major',labelsize=14)

plt.show()

2.散点图:matplotlib.pyplot.scatter()
示例:

#设置图形大小分辨率等
plt.figure(figsize=(10,6),dpi=128)
plt.scatter(rw.x_values,rw.y_values,c=point_number,cmap=plt.cm.Blues,edgecolor='none',s=2)
#设置原点和最后一个点
plt.scatter(0,0,c='red',edgecolor='none',s=200)
plt.scatter(rw.x_values[-1],rw.y_values[-1],c='red',edgecolor='none',s=200)
plt.show()

3.直方图:pygal.Bar()
示例:

java_style=LS('#336699',base_style=LCS)
chart=pygal.Bar(style=java_style,x_label_rotation=45,show_legend=False)
chart.title='最受欢迎的Java项目'
chart.x_labels=names

chart.add('java',stars
file_path='C:\\Users\\luna\\Desktop\\documents\\data_science\\data_science\\python\\Python_first\\project_data\\下载数据\\使用API\\Java项目.svg'
chart.render_to_file(file_path)

4.地图:pygal.maps.world.World()
示例:

world_map_style=RotateStyle('#336699',base_style=LightColorizedStyle)           
world_map=pygal.maps.world.World(style=world_map_style)
world_map.title='2010年世界人口地图'
world_map.add('0-10m',cc_pops_1)
world_map.add('10m-1bn',cc_pops_2)
world_map.add('>1bn',cc_pops_3)

file_path='C:\\Users\\luna\\Desktop\\documents\\data_science\\data_science\\python\\Python_first\\project_data\\下载数据\\世界人口地图\\世界人口.svg'
world_map.render_to_file(file_path)
上一篇下一篇

猜你喜欢

热点阅读