python可视化入门 plotly

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装 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          62.0      '-     98.2        78.2

图片

exam

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值