安装 plotly
pip install plotly
导入plotly模块
import plotly.graph_objects as go
import plotly.offline as of # 这个为离线模式的导入方法
import pandas as pd #使用pandas处理csv数据
example1 Scatter
通过Scatter方法画折线图:
data = pd.read_csv(r'C:\Users\Administrator\Desktop\data\nz_weather.csv')
print(data.head()) #显示5条数据
# Scatter
line1 = go.Scatter(y=data['Auckland'], x=data['DATE'], name='Auckland') # name定义每条线的名称
line2 = go.Scatter(y=data['Wellington'], x=data['DATE'], name='Wellington')
fig = go.Figure([line1, line2])
fig.update_layout(
title = 'New Zealand Weather', #定义生成的plot 的标题
xaxis_title = 'DATE', #定义x坐标名称
yaxis_title = 'Weather' #定义y坐标名称
)
of.plot(fig)
使用数据:
DATE Auckland Christchurch Dunedin Hamilton Wellington
0 2000-01 115.4 47.2 174.8 96.2 91.8
1 2000-02 8.4 25.2 41 8.2 35.2
2 2000-03 57.2 60.8 74.2 33.8 53.4
3 2000-04 106.8 58.2 50 129.6 109.8
4 2000-05 128.2 &

这篇博客介绍了Python中使用Plotly进行数据可视化的入门知识,包括安装Plotly库,导入模块,以及通过示例展示如何画折线图、条形图、统计次数、制作图表、生成饼图和3D plot,还涉及了使用Express模块简化绘图过程以及如何生成地图数据。
最低0.47元/天 解锁文章
4万+

被折叠的 条评论
为什么被折叠?



