

用 Python 教你画花样图
source link: http://www.justdopython.com/2020/12/11/Python-Plotly-express-lines/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

在之前的一篇文章Python可视化神器-Plotly动画展示展现了可视化神器-Plotly的动画的基本应用,本文介绍如何在Python中使用 Plotly 创建地图并在地图上标相应的线。对于 Plotly的详解请参阅之前的文章。
地球仪加线
根据地球仪的区域显示在相应的位置图形上加上线条,完美的线性地球仪详细代码如下:
import plotly.express as px
df = px.data.gapminder().query("year == 2007")
fig = px.line_geo(df, locations="iso_alpha",
color="continent", # "continent" is one of the columns of gapminder
projection="orthographic")
fig.show()
显示结果为:**
地图上加线
绘画出相应的地图后添加经纬度,再根据经纬度绘画出相应的线条, 详细代码如下:
import plotly.graph_objects as go
fig = go.Figure(data=go.Scattergeo(
lat = [3.86, 53.55],
lon = [73.66, 135.05],
mode = 'lines',
line = dict(width = 2, color = 'red'),
))
fig.update_layout(
geo = dict(
resolution = 50,
showland = True,
showlakes = True,
landcolor = 'rgb(203, 203, 203)',
countrycolor = 'rgb(204, 204, 204)',
lakecolor = 'rgb(255, 255, 255)',
projection_type = "equirectangular",
coastlinewidth = 3,
lataxis = dict(
range = [20, 60],
showgrid = True,
dtick = 10
),
lonaxis = dict(
range = [-100, 20],
showgrid = True,
dtick = 20
),
)
)
fig.show()
显示结果如下:
最后的福利-3D图鉴赏
最后加入一个3D图像鉴赏,制作图像详细代码如下:
# 导入包
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import numpy as np
N = 50
fig = make_subplots(rows=2, cols=2,
specs=[[{'is_3d': True}, {'is_3d': True}],
[{'is_3d': True}, {'is_3d': True}]],
print_grid=False)
for i in [1,2]:
for j in [1,2]:
fig.append_trace(
go.Mesh3d(
x=(50*np.random.randn(N)),
y=(20*np.random.randn(N)),
z=(40*np.random.randn(N)),
opacity=0.5,
),
row=i, col=j)
fig.update_layout(width=700, margin=dict(r=9, l=9, b=9, t=9))
# 将左上角子图中的比率固定为立方体
fig.update_layout(scene_aspectmode='cube')
# 手动强制z轴显示为其他两个的两倍大
fig.update_layout(scene2_aspectmode='manual',
scene2_aspectratio=dict(x=1, y=1, z=2))
# 绘制轴线与轴线范围的比例成比例
fig.update_layout(scene3_aspectmode='data')
# 使用“data”作为默认值自动生成比例良好的内容
fig.update_layout(scene4_aspectmode='auto')
#显示
fig.show()
显示结果如下:
希望今天文章和实战对大家有所帮助,在以后的成神路上越来越顺利!
示例代码:https://github.com/JustDoPython/python-examples/tree/master/chaoxi/Plotly-express
Recommend
-
115
什么是产品架构图产品架构图是产品经理用来表达自己产品设计机制的一张概念图:它将可...
-
124
这是很久以前发布在简书平台上的一篇有关内存泄漏的译文。这篇文章提及的8种内存泄漏的场景,现在来看依旧很经典。为了避免内存泄漏,开发过程中需要谨慎谨慎再谨慎。同时,保持良好的开发习惯也至关重要。 具有垃圾回收特性的语言(如Java)的优点在于,它使得开发...
-
94
花样年二次转型:弯道拿地扩张,轻资产业务超四成 2017-12-25 14:46:50 来源: 时代周报...
-
108
你们疯狂转花样滑...是时候把手里珍藏10年的神作掏出来了。魔法少女——浅田真央。
-
108
陈一舟花样割韭菜 中小股东要联合起诉他
-
72
这世界胡说八道的人还少吗
-
30
日本漫画家佐藤夕子又来教你画插图了,真的好简单呢。(twi:makaidaibouken4)
-
73
■本报记者 谢若琳 陈 炜 2003年的春天,一档名为《电子竞技世界》的节目在央视体育频道上线,主持人段暄带着CS、War3,一度开启了大众对电竞的关注。 15年后的今天,彼时活跃在节目中的电竞选手,已先后退出职业舞台。而经历...
-
73
-
9
之前我们出过一篇文章,向大家推荐了知名 CG 艺术网站 Artstation 旗下的教育品牌 Artstation Learning。2022 年初 Artstation Learning 宣布站内课程全部开放,永久免费供所有人学习。这些课程都...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK