SoFunction
Updated on 2024-11-16

An article that teaches you to draw pattern diagrams using Python

preamble

In a previous article Python visualization artifacts - Plotly animation show visualization artifacts - Plotly animation of the basic applications, this article describes how to use Plotly in Python to create maps and mark the corresponding lines on the map.

Globe Plus Line

According to the regional display of the globe in the corresponding location of the graphic with lines, the perfect linear globe detailed code is as follows:

`import  as px
df = ("year == 2007")
fig = px.line_geo(df, locations="iso_alpha",
color="continent", 
# "continent" is one of the columns of gapminder
projection="orthographic")
` 

The results are displayed as follows:**

图片.png

Add lines to the map

Add latitude and longitude after drawing the corresponding map, and then draw the corresponding lines according to the latitude and longitude, the detailed code is as follows:

import

plotly.graph_objects

as

go

fig = (data=(
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
),
)
)

``

The results are displayed as follows:

图片.png

图片.png

Final Benefit - 3D Drawing Appreciation

Finally add a 3D image appreciation to create the image detailed code is as follows:

# import packageimport

plotly.graph_objects

as

go

from



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*(N)),
y=(20*(N)),
z=(40*(N)),
opacity=0.5,
),
row=i, col=j)

`fig.update_layout(width=700, margin=dict(r=9, l=9, b=9, t=9))
# Fix the ratios in the upper left subplot to cubes
fig.update_layout(scene_aspectmode='cube')
# Manually force the z-axis display to be twice as large as the other two
fig.update_layout(scene2_aspectmode='manual',
scene2_aspectratio=dict(x=1, y=1, z=2))
# Drawing axes proportional to the scale of the axis range
fig.update_layout(scene3_aspectmode='data')
# Automatically generate well-proportioned content using "data" as the default value
fig.update_layout(scene4_aspectmode='auto')
#Display
` 

The results are displayed as follows:

图片.png

图片.png

summarize

To this point this article on the use of Python to draw a pattern on the article is introduced to this, more related Python to draw a pattern on the content please search for my previous articles or continue to browse the following related articles I hope that you will support me more in the future!