How to make a globe with Python

Python is really powerful and surprisingly powerful. What it can do includes crawling, data analysis, data visualization, games, etc. These functions are widely used in actual use, and develop programs Pay attention to the beauty and cool effects of the page. Today’s article will bring a different visual feast to readers and friends. Interested friends are welcome to try it together.

Written in the previous words: The installation and use of pyecharts are introduced in the previous article The solution to the installation and installation of pyecharts in Python.

pyecharts is very powerful. You only need to import the corresponding module and configure the corresponding options to generate the corresponding hypertext file, which can be accessed with a browser! Please see below for specific examples

Feast 1-2D world map

Let's take a 2D look first~

The implementation code is as follows:

from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker

c =(Map(init_opts=opts.InitOpts(width='1500px', height='1200px',bg_color='#E0EEEE'))
 # Load the world map instance
 . add("world map",[list(z)for z inzip(Faker.country, Faker.values())],"world")
 # Don't show map logo
 . set_series_opts(label_opts=opts.LabelOpts(is_show=False)).set_global_opts(
 # Configuration item title setting
 title_opts=opts.TitleOpts(title="World map example"),
 visualmap_opts=opts.VisualMapOpts(max_=200))
 # Generate hypertext file
 . render("world_map.html"))

Feast 2-China 3D Map

Realize 3D rendering of China map by importing Map3D, etc.:

The implementation code is as follows:

from pyecharts import options as opts
from pyecharts.charts import Map3D
from pyecharts.globals import ChartType

c =(Map3D(init_opts=opts.InitOpts(width='1300px', height='1300px',bg_color='#EBEBEB')).add_schema(
 itemstyle_opts=opts.ItemStyleOpts(
 color="#CDBA96",
 opacity=1,
 border_width=0.8,
 border_color="rgb(62,215,213)",),
 map3d_label=opts.Map3DLabelOpts(
 is_show=True,
 text_style=opts.TextStyleOpts(
 color="#104E8B", font_size=16, background_color="rgba(0,0,0,0)"),),
 emphasis_label_opts=opts.LabelOpts(is_show=True),
 light_opts=opts.Map3DLightOpts(
 main_color="#FFEBCD",
 main_intensity=1.2,
 is_main_shadow=False,
 main_alpha=55,
 main_beta=10,
 ambient_intensity=0.3,),).add(series_name="", data_pair="", maptype=ChartType.MAP3D)
 # Set map properties globally
 . set_global_opts(
 title_opts=opts.TitleOpts(title="National administrative division map"),
 visualmap_opts=opts.VisualMapOpts(is_show=False),
 tooltip_opts=opts.TooltipOpts(is_show=True),).render("map3d_china_base.html"))

Feast 3-Guizhou Map

Now use another way to realize the map of my hometown, let’s take a look~

The code is implemented as follows:

# Write the latitude and longitude of each region in the province
example_data =[[[106.70722,26.59820,1000],[106.63024,26.64702,1000]],[[104.83023,26.59336],[106.92723,27.72545]],[[105.30504,27.29847],[107.52034,26.29322]],[[107.89868,26.52881],[104.948571,25.077502]],[[105.9462,26.25367],[109.18099,27.69066]],]
# Add 3D map
c =(Map3D(init_opts=opts.InitOpts(width='1200px', height='1200px')).add_schema(
 maptype="Guizhou",
 itemstyle_opts=opts.ItemStyleOpts(
 color="rgb(5,101,123)",
 opacity=1,
 border_width=0.8,
 border_color="rgb(62,215,213)",),
 light_opts=opts.Map3DLightOpts(
 main_color="#fff",
 main_intensity=1.2,
 is_main_shadow=True,
 main_alpha=55,
 main_beta=10,
 ambient_intensity=0.3,),
 view_control_opts=opts.Map3DViewControlOpts(center=[-10,0,10]),
 post_effect_opts=opts.Map3DPostEffectOpts(is_enable=True),).add(
 series_name="",
 data_pair=example_data,
 type_=ChartType.LINES3D,
 effect=opts.Lines3DEffectOpts(
 is_show=True,
 period=4,
 trail_width=3,
 trail_length=0.5,
 trail_color="#f00",
 trail_opacity=1,),
 label_opts=opts.LabelOpts(is_show=True),).set_global_opts(title_opts=opts.TitleOpts(title="Map3D-GuiZhou3D")).render("guizhou_map_3d.html"))

Feast 4-Realization of Global Village

Let's take a look at the rotating earth^^

The implementation code is as follows:

import pyecharts.options as opts
from pyecharts.charts import MapGlobe
from pyecharts.faker import POPULATION

data =[x for _, x in POPULATION[1:]]
low, high =min(data),max(data)
c =(MapGlobe(init_opts=opts.InitOpts(width='1000px', height='1000px',bg_color='#FFFAFA',)).add_schema().add(
 maptype="world",
 series_name="World Population",
 data_pair=POPULATION[1:],
 is_map_symbol_show=True,
 label_opts=opts.LabelOpts(is_show=True),).set_global_opts(
 title_opts=opts.TitleOpts(title="3D earth example"),
 # Set earth properties
 visualmap_opts=opts.VisualMapOpts(
 min_=low,
 max_=high,
 range_text=["max","min"],
 is_calculable=True,
 range_color=["lightskyblue","yellow","orangered"],)).render("world_map_3d.html"))

to sum up

I hope that today's sharing will bring you a different visual enjoyment, and at the same time, partners should not forget to practice more. Practice is the only criterion for testing truth!

reference

http://gallery.pyecharts.org/#/Map3D/

Sample code (https://github.com/JustDoPython/python-examples/tree/master/chaoxi/Earth_view)

So far this article on the method of making a globe with Python is introduced. For more related python globe content, please search for previous articles on ZaLou.Cn or continue to browse related articles below. Hope you will support ZaLou.Cn more in the future!

Recommended Posts

How to make a globe with Python
How to process excel table with python
How to sort a dictionary in python
How to get started quickly with Python
How to simulate gravity in a Python game
How to play happily with Python3 on Ubuntu
Python how to delete rows with empty columns
How to write a confession program in python
How to read and write files with Python
How to deal with python file reading failure
How to comment python code
How to learn python quickly
How to start a blog with Hexo on Ubuntu 14.04
How to uninstall python plugin
How to understand a list of numbers in python
How to understand python objects
How to use python tuples
How to create a Python virtual environment in Ubuntu 14.04
How to find the area of a circle in python
How to set up a firewall with UFW on Ubuntu 14.04
python how to view webpage code
How to use python thread pool
How to write python configuration file
How to wrap in python code
How to save the python program
How to omit parentheses in Python
How to install Python 3.8 on CentOS 8
How to install Python 3.8 on Ubuntu 18.04
How to write classes in python
How to filter numbers in python
Centos6.7 comes with python upgrade to
How to read Excel in Python
How to install Python on CentOS 8
How to solve python dict garbled
How to view errors in python
How to write return in python
How to view the python module
How to understand variables in Python
How to clear variables in python
How to understand python object-oriented programming
How to use SQLite in Python
A practical guide to Python file handling
How to verify successful installation of python
How to use and and or in Python
How to delete cache files in python
How to introduce third-party modules in Python
How to represent null values in python
How to save text files in python
Use Python to make airplane war games
A quick introduction to Python regular expressions
How to use PYTHON to crawl news articles
A complete guide to Python web development
How to write win programs in python
How to run id function in python
How to install third-party modules in Python
How to custom catch errors in python
How to write try statement in python
How to define private attributes in Python
R&D: How To Install Python 3 on CentOS 7
How to add custom modules in Python
How to understand global variables in Python