plotly可视化案例
时间: 2023-12-17 14:02:10 浏览: 28
下面是一个使用 Plotly 库进行可视化的例子:
```python
import plotly.express as px
import pandas as pd
# 读取数据
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv')
# 创建动态图表
fig = px.scatter(df, x="gdpPercap", y="lifeExp",
size="pop", color="continent",
hover_name="country", log_x=True, size_max=60,
animation_frame="year", range_x=[100,100000], range_y=[20,90])
# 显示图表
fig.show()
```
这个例子使用了 Gapminder 数据集,展示了全球各国家的人均 GDP、人均寿命和人口数量之间的关系,同时还可以通过动态效果展示不同年份的数据。
相关问题
jupyter notebook可视化案例
Jupyter Notebook是一个非常流行的开源交互式笔记本,它支持多种编程语言,例如Python、R和Julia等,可用于数据分析、数据可视化、机器学习和深度学习等领域。
下面是一些Jupyter Notebook可视化案例:
1. 数据可视化:通过使用Python的Matplotlib、Seaborn、Plotly等库,可以在Jupyter Notebook中可视化数据。这些库提供了各种图表类型,如折线图、柱状图、散点图等,可以帮助用户更好地理解和分析数据。
2. 交互式可视化:通过使用Bokeh、Plotly和Altair等库,可以创建交互式可视化效果,使用户能够与数据进行交互。例如,用户可以通过滑动条或下拉菜单来过滤和探索数据。
3. 地图可视化:通过使用Folium和GeoPandas等库,可以在Jupyter Notebook中绘制地图和地理数据。这些库提供了各种功能,如标记、热图、聚类等,可以帮助用户更好地理解地理信息。
python爬虫建筑案例可视化案例
以下是一个Python爬虫建筑案例的可视化案例:
1. 爬取数据
我们可以使用Python爬虫爬取一些建筑的信息,例如高度、建造年份和位置等。这里我们以Emporis网站上的建筑信息为例:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://www.emporis.com/statistics/tallest-buildings'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
buildings = []
for building in soup.find_all('div', class_='statistics__building'):
name = building.find('h4').text
height = building.find('div', class_='statistics__value').text
year = building.find_all('div', class_='statistics__value')[1].text
location = building.find('div', class_='statistics__location').text
buildings.append({'name': name, 'height': height, 'year': year, 'location': location})
```
2. 可视化数据
接下来,我们可以使用plotly库将爬取到的数据可视化出来:
```python
import plotly.graph_objs as go
from plotly.subplots import make_subplots
fig = make_subplots(rows=1, cols=2, specs=[[{'type': 'xy'}, {'type': 'mapbox'}]])
x = [building['name'] for building in buildings]
y = [float(building['height'].replace(',', '')) for building in buildings]
z = [building['location'] for building in buildings]
year = [int(building['year']) for building in buildings]
fig.add_trace(go.Bar(x=x, y=y), row=1, col=1)
fig.add_trace(go.Scattermapbox(lat=[40.7128], lon=[-74.0060], mode='markers', marker={'size': 10}),
row=1, col=2)
fig.update_layout(mapbox_style='open-street-map', mapbox_center_lat=40.7128, mapbox_center_lon=-74.0060,
mapbox_zoom=2)
fig.show()
```
这段代码将建筑的高度以柱状图的形式展示出来,建筑的位置以地图的形式展示出来。通过这种方式,我们可以更加直观地观察到各个建筑之间的高度差异以及它们的位置分布情况。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)