In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how matplotlib to achieve the 3D effect of Basemap, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Matplotlib is a drawing plug-in in python
Matplotlib supports the effect of two-dimensional map, but also supports the effect of three-dimensional map. In the production of big data, you can take the map as the bottom and add the effect of a bar chart next to it to achieve a three-dimensional effect. There are many ready-made libraries in python, which is more convenient in development and can be directly used by import.
The specific implementation code is as follows:
# coding=utf-8
# reference the corresponding drawing class library
Import matplotlib.pyplot as plt
From mpl_toolkits.mplot3d import Axes3D
From mpl_toolkits.basemap import Basemap
From matplotlib.collections import PolyCollection
Import numpy as np
# initialize a basic map and 3D axis
Map = Basemap ()
Fig = plt.figure ()
Ax = Axes3D (fig)
# set 3D orientation angle, height and distance
Ax.azim = 270
Ax.elev = 50
Ax.dist = 8
# draw the coastline and national boundaries of the map on the bottom
Ax.add_collection3d (map.drawcoastlines (linewidth=0.25))
Ax.add_collection3d (map.drawcountries (linewidth=0.35))
# convert a face on a map into a picture on a three-dimensional axis
Polys = []
For polygon in map.landpolygons:
Polys.append (polygon.get_coords ())
Lc = PolyCollection (polys, edgecolor='black'
Facecolor='#123456', closed=False)
Ax.add_collection3d (lc)
# simulate bar chart data on a map, with coordinates according to longitude and latitude
Lons = np.array ([- 13.7,10.8,13.2,96.8,7.99,7.5,-17.3,3.7])
Lats = np.array ([9.6,6.3,8.5,32.7,12.5,8.9,14.7,40.39])
Cases = np.array ([1971, 7069, 6073, 4, 6, 20, 1,1])
Deaths = np.array ([1192, 2964, 1250, 1,5,8,0,0])
Places = np.array (['Guinea',' Liberia', 'Sierra Leone','United States',' Mali', 'Nigeria',' Senegal', 'Spain'])
X, y = map (lons, lats)
# the effect of adding a bar chart
Ax.bar3d (x, y, np.zeros (len (x)), 2, 2, deaths, color= 'rust, alpha=0.75)
Plt.show ()
The above is all the content of the article "how to achieve the 3D effect of Basemap by matplotlib". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.