1.折線圖:matplotlib.pyplot.plot()
#繪制圖形
#設(shè)置圖形大小、長寬比例
figure=plt.figure(dpi=128,figsize=(12,6))
#設(shè)置x軸y軸數(shù)據(jù)和線條顏色
plt.plot(dates_1,highs_1,c='red')
plt.plot(dates_1,lows_1,c='red')
#設(shè)置兩條線之間填充色
plt.fill_between(dates_1,highs_1,lows_1,facecolor='red',alpha=0.1)
#圖像格式
plt.title('2014年每日最高溫度、最低溫度、平均溫度-死亡谷-錫特卡',fontsize=24)
plt.xlabel('日期',fontsize=16)
#繪制斜的日期標(biāo)簽
figure.autofmt_xdate()
plt.ylabel('溫度',fontsize=16)
plt.tick_params(axis='both',which='major',labelsize=14)
plt.show()
2.散點(diǎn)圖:matplotlib.pyplot.scatter()
示例:
#設(shè)置圖形大小分辨率等
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)
#設(shè)置原點(diǎn)和最后一個點(diǎn)
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項(xiàng)目'
chart.x_labels=names
chart.add('java',stars
file_path='C:\\Users\\luna\\Desktop\\documents\\data_science\\data_science\\python\\Python_first\\project_data\\下載數(shù)據(jù)\\使用API\\Java項(xiàng)目.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\\下載數(shù)據(jù)\\世界人口地圖\\世界人口.svg'
world_map.render_to_file(file_path)