Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Python to draw pattern

Shulou Source: shulou.com Published: 2022-06-02 19:39:52 10月04日 Update

This article introduces the relevant knowledge of "how to use Python to draw patterns". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Globe wiring

According to the display of the globe area, add lines to the corresponding position graph, the perfect linear globe detailed code is as follows:

`import plotly.express as pxdf = px.data.gapminder.query ("year = = 2007") fig = px.line_geo (df, locations= "iso_alpha", color= "continent", # "continent" is one of the columns of gapminderprojection= "orthographic") fig.show`

The display result is: * *

Add lines to the map

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

Importplotly.graph_objectsasgofig = 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 = 3herolataxis = dict (range = [20,60], showgrid = True,dtick = 10), lonaxis = dict (range = [- 100,20], showgrid = True,dtick = 20),) `fig.show`

The display results are as follows:

The final benefit-3D picture appreciation

Finally, add a 3D image appreciation, and the detailed code for making the image is as follows:

# Import package importplotly.graph_objectsasgofromplotly.subplotsimportmake_subplotsimportnumpyasnpN = 50fig = 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 for j in 2]: fig.append_trace (go.Mesh4d (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 (ritual 9, lumped 9, bimodal 9, tweak 9)) # fix the ratio in the upper left subgraph to the cube fig.update_layout (scene_aspectmode='cube') # manually force the z axis to be displayed as twice the size of the other two fig.update_layout (scene2_aspectmode='manual',scene2_aspectratio=dict (x, y) 1 Fig.update_layout (scene3_aspectmode='data') # use "data" as the default value to automatically generate well-proportioned content fig.update_layout (scene4_aspectmode='auto') # display fig.show`

The display results are as follows:

This is the end of the content of "how to draw patterns with Python". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Code content earth globe scale results patterns images maps more knowledge lines latitude and longitude painting axis appreciation practical good successful learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Information NVidia Redmi macOS