Skip to content

Commit

Permalink
3d map (pyecharts#1213)
Browse files Browse the repository at this point in the history
* ✨ globe in 3d

* 💚 test map3d and map globe

* 💄 update import list

* 📚 add render examples

* 💄 update coding style

* Format: code
  • Loading branch information
chfw authored and chenjiandongx committed Jun 27, 2019
1 parent 654bdbd commit 9216aa7
Show file tree
Hide file tree
Showing 18 changed files with 536 additions and 10 deletions.
238 changes: 238 additions & 0 deletions example/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,241 @@ class Collector:
@staticmethod
def funcs(fn):
Collector.charts.append((fn, fn.__name__))


POPULATION = [
["Country (or dependency)", "Population\n(2019)"],
["China", 1420062022],
["India", 1368737513],
["United States", 329093110],
["Indonesia", 269536482],
["Brazil", 212392717],
["Pakistan", 204596442],
["Nigeria", 200962417],
["Bangladesh", 168065920],
["Russia", 143895551],
["Mexico", 132328035],
["Japan", 126854745],
["Ethiopia", 110135635],
["Philippines", 108106310],
["Egypt", 101168745],
["Vietnam", 97429061],
["DR Congo", 86727573],
["Turkey", 82961805],
["Iran", 82820766],
["Germany", 82438639],
["Thailand", 69306160],
["United Kingdom", 66959016],
["France", 65480710],
["Tanzania", 60913557],
["Italy", 59216525],
["South Africa", 58065097],
["Myanmar", 54336138],
["Kenya", 52214791],
["South Korea", 51339238],
["Colombia", 49849818],
["Spain", 46441049],
["Uganda", 45711874],
["Argentina", 45101781],
["Ukraine", 43795220],
["Algeria", 42679018],
["Sudan", 42514094],
["Iraq", 40412299],
["Poland", 38028278],
["Canada", 37279811],
["Afghanistan", 37209007],
["Morocco", 36635156],
["Saudi Arabia", 34140662],
["Peru", 32933835],
["Uzbekistan", 32807368],
["Venezuela", 32779868],
["Malaysia", 32454455],
["Angola", 31787566],
["Mozambique", 31408823],
["Ghana", 30096970],
["Nepal", 29942018],
["Yemen", 29579986],
["Madagascar", 26969642],
["North Korea", 25727408],
["Côte d'Ivoire", 25531083],
["Cameroon", 25312993],
["Australia", 25088636],
["Taiwan", 23758247],
["Niger", 23176691],
["Sri Lanka", 21018859],
["Burkina Faso", 20321560],
["Malawi", 19718743],
["Mali", 19689140],
["Romania", 19483360],
["Kazakhstan", 18592970],
["Syria", 18499181],
["Chile", 18336653],
["Zambia", 18137369],
["Guatemala", 17577842],
["Zimbabwe", 17297495],
["Netherlands", 17132908],
["Ecuador", 17100444],
["Senegal", 16743859],
["Cambodia", 16482646],
["Chad", 15814345],
["Somalia", 15636171],
["Guinea", 13398180],
["South Sudan", 13263184],
["Rwanda", 12794412],
["Benin", 11801595],
["Tunisia", 11783168],
["Burundi", 11575964],
["Belgium", 11562784],
["Cuba", 11492046],
["Bolivia", 11379861],
["Haiti", 11242856],
["Greece", 11124603],
["Dominican Republic", 10996774],
["Czechia", 10630589],
["Portugal", 10254666],
["Jordan", 10069794],
["Sweden", 10053135],
["Azerbaijan", 10014575],
["United Arab Emirates", 9682088],
["Hungary", 9655361],
["Honduras", 9568688],
["Belarus", 9433874],
["Tajikistan", 9292000],
["Austria", 8766201],
["Serbia", 8733407],
["Switzerland", 8608259],
["Papua New Guinea", 8586525],
["Israel", 8583916],
["Togo", 8186384],
["Sierra Leone", 7883123],
["Hong Kong", 7490776],
["Laos", 7064242],
["Bulgaria", 6988739],
["Paraguay", 6981981],
["Libya", 6569864],
["El Salvador", 6445405],
["Nicaragua", 6351157],
["Kyrgyzstan", 6218616],
["Lebanon", 6065922],
["Turkmenistan", 5942561],
["Singapore", 5868104],
["Denmark", 5775224],
["Finland", 5561389],
["Congo", 5542197],
["Slovakia", 5450987],
["Norway", 5400916],
["Eritrea", 5309659],
["State of Palestine", 5186790],
["Oman", 5001875],
["Costa Rica", 4999384],
["Liberia", 4977720],
["Ireland", 4847139],
["Central African Republic", 4825711],
["New Zealand", 4792409],
["Mauritania", 4661149],
["Kuwait", 4248974],
["Panama", 4226197],
["Croatia", 4140148],
["Moldova", 4029750],
["Georgia", 3904204],
["Puerto Rico", 3654978],
["Bosnia and Herzegovina", 3501774],
["Uruguay", 3482156],
["Mongolia", 3166244],
["Albania", 2938428],
["Armenia", 2936706],
["Jamaica", 2906339],
["Lithuania", 2864459],
["Qatar", 2743901],
["Namibia", 2641996],
["Botswana", 2374636],
["Lesotho", 2292682],
["Gambia", 2228075],
["Gabon", 2109099],
["North Macedonia", 2086720],
["Slovenia", 2081900],
["Guinea-Bissau", 1953723],
["Latvia", 1911108],
["Bahrain", 1637896],
["Swaziland", 1415414],
["Trinidad and Tobago", 1375443],
["Equatorial Guinea", 1360104],
["Timor-Leste", 1352360],
["Estonia", 1303798],
["Mauritius", 1271368],
["Cyprus", 1198427],
["Djibouti", 985690],
["Fiji", 918757],
["Réunion", 889918],
["Comoros", 850910],
["Bhutan", 826229],
["Guyana", 786508],
["Macao", 642090],
["Solomon Islands", 635254],
["Montenegro", 629355],
["Luxembourg", 596992],
["Western Sahara", 582478],
["Suriname", 573085],
["Cabo Verde", 560349],
["Micronesia", 536579],
["Maldives", 451738],
["Guadeloupe", 448798],
["Brunei", 439336],
["Malta", 433245],
["Bahamas", 403095],
["Belize", 390231],
["Martinique", 385320],
["Iceland", 340566],
["French Guiana", 296847],
["French Polynesia", 288506],
["Vanuatu", 288017],
["Barbados", 287010],
["New Caledonia", 283376],
["Mayotte", 266380],
["Sao Tome & Principe", 213379],
["Samoa", 198909],
["Saint Lucia", 180454],
["Guam", 167245],
["Channel Islands", 166828],
["Curaçao", 162547],
["Kiribati", 120428],
["St. Vincent & Grenadines", 110488],
["Tonga", 110041],
["Grenada", 108825],
["Aruba", 106053],
["U.S. Virgin Islands", 104909],
["Antigua and Barbuda", 104084],
["Seychelles", 95702],
["Isle of Man", 85369],
["Andorra", 77072],
["Dominica", 74679],
["Cayman Islands", 63129],
["Bermuda", 60833],
["Greenland", 56673],
["Saint Kitts & Nevis", 56345],
["American Samoa", 55727],
["Northern Mariana Islands", 55246],
["Marshall Islands", 53211],
["Faeroe Islands", 49692],
["Sint Maarten", 40939],
["Monaco", 39102],
["Liechtenstein", 38404],
["Turks and Caicos", 36461],
["Gibraltar", 34879],
["San Marino", 33683],
["British Virgin Islands", 32206],
["Caribbean Netherlands", 25971],
["Palau", 22206],
["Cook Islands", 17462],
["Anguilla", 15174],
["Wallis & Futuna", 11617],
["Tuvalu", 11393],
["Nauru", 11260],
["Saint Pierre & Miquelon", 6375],
["Montserrat", 5220],
["Saint Helena", 4096],
["Falkland Islands", 2921],
["Niue", 1628],
["Tokelau", 1340],
["Holy See", 799],
]
3 changes: 3 additions & 0 deletions example/map3d_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from pyecharts.charts import Map3D

Map3D().add_schema().render()
28 changes: 28 additions & 0 deletions example/map_globe_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pyecharts.options as opts
from example.commons import POPULATION
from pyecharts.charts import MapGlobe

high = max([x for _, x in POPULATION[1:]])
low = min([x for _, x in POPULATION[1:]])

m = (
MapGlobe()
.add_schema()
.add(
maptype="world",
series_name="World Population",
data_pair=POPULATION[1:],
is_map_symbol_show=False,
label_opts=opts.LabelOpts(is_show=False),
)
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(
min_=low,
max_=high,
range_text=["max", "min"],
is_calculable=True,
range_color=["lightskyblue", "yellow", "orangered"],
)
)
)
m.render()
2 changes: 2 additions & 0 deletions pyecharts/charts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
# 3d charts
from ..charts.threeD_charts.bar3D import Bar3D
from ..charts.threeD_charts.line3D import Line3D
from ..charts.threeD_charts.map3D import Map3D
from ..charts.threeD_charts.map_globe import MapGlobe
from ..charts.threeD_charts.scatter3D import Scatter3D
from ..charts.threeD_charts.surface3D import Surface3D

Expand Down
6 changes: 5 additions & 1 deletion pyecharts/charts/basic_charts/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ...globals import ChartType


class Map(Chart):
class MapMixin:
"""
<<< Map >>>
Expand Down Expand Up @@ -55,3 +55,7 @@ def add(
}
)
return self


class Map(Chart, MapMixin):
pass
2 changes: 2 additions & 0 deletions pyecharts/charts/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ def __init__(self, init_opts: types.Init = opts.InitOpts()):
self.options.update(visualMap=opts.VisualMapOpts().opts)
self._3d_chart_type: Optional[str] = None # 3d chart type,don't use it directly


class ThreeAxisChart(Chart3D):
def add(
self,
series_name: str,
Expand Down
4 changes: 2 additions & 2 deletions pyecharts/charts/threeD_charts/bar3D.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from ... import types
from ...charts.chart import Chart3D
from ...charts.chart import ThreeAxisChart
from ...options import InitOpts


class Bar3D(Chart3D):
class Bar3D(ThreeAxisChart):
"""
<<< 3D Bar-Chart >>>
"""
Expand Down
4 changes: 2 additions & 2 deletions pyecharts/charts/threeD_charts/line3D.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from ... import types
from ...charts.chart import Chart3D
from ...charts.chart import ThreeAxisChart
from ...options import InitOpts


class Line3D(Chart3D):
class Line3D(ThreeAxisChart):
"""
<<< 3D Line-Chart >>>
"""
Expand Down
Loading

0 comments on commit 9216aa7

Please sign in to comment.