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