In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "how to use Python to quickly draw poster-level maps", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use Python to quickly draw poster-level maps" this article.
1 introduction
Based on the Python drawing library with rich functions and high degrees of freedom, such as matplotlib, we can complete a variety of artistic visualization works. I have studied a lot of cases in a series of articles about data visualization in imitation.
And today I'm going to introduce to you the Python library prettymaps is very interesting, based on it, we only need simple code to map any area of the earth with given coordinates and range.
2 making poster-level map quickly by using prettymaps
Unfortunately, prettymaps cannot be installed directly through pip or conda, but it can be installed from the source code repository with pip and git. For domestic users, you can use the following statement to quickly install from the image address of github:
Pip install git+ https://hub.fastgit.org/marceloprates/prettymaps.git
After the installation is complete, if the following statements are executed correctly, congratulations on your installation:
Several ways to use from prettymaps import * 2.1prettymaps
Prettymaps does not need users to prepare their own data, and automatically acquires vector data within the corresponding range from OpenStreetMap as drawing material according to the coordinates and range set by the user. There are mainly several ways to use it:
2.1.1 Circular mode
The simplest drawing mode in prettymaps is circular mode. We only need to pass in the longitude and latitude coordinates of the center point and the radius range (in meters). The following example is from the official sample program. I changed its location to an outward range of 2500 meters from the Shanghai Bund:
From prettymaps import * from matplotlib import pyplot as plt# create bed fig, ax = plt.subplots (figsize = (12,12), constrained_layout = True) layers = plot ((31.23346, 121.492154), # center coordinates, format: (latitude, longitude) radius = 2500, # radius ax = ax, # bind bed layers = {'perimeter': {}, # control drawing mode {}, which is equivalent to circular drawing mode # the following parameters are used to define vector layer features obtained from OsmStreetMap selection If you don't know, you can copy 'streets': {' custom_filter':'["highway" ~ "motorway | trunk | primary | secondary | tertiary | residential | service | unclassified | pedestrian | footway"], 'width': {' motorway': 5, 'trunk': 5,' primary': 4.5, 'secondary': 4 'tertiary': 3,' residential': 3, 'service': 2,' unclassified': 2, 'pedestrian': 2,' footway': 1,}}, 'building': {' tags': {'building': True,' landuse': 'construction'} 'union': False},' water': {'tags': {' natural': ['water',' bay']}, 'green': {' tags': {'landuse':' grass', 'natural': [' island', 'wood'],' leisure': 'park'}},' forest': {'tags': {' landuse': 'forest'}} 'parking': {' tags': {'amenity':' parking', 'highway':' pedestrian', 'man_made':' pier'}}, # the following parameters are used to define the styles of different vector layers in OpenStreetMap If you find it troublesome to copy the following official example directly, you can drawing_kwargs = {'background': {' fc':'# F2F4CBsituation, 'ec':' dadbc1', 'hatch':' ooo...', 'zorder':-1},' perimeter': {'fc':' # F2F4CBbath, 'ec':' # dadbc1', 'lw': 0,' hatch': 'ooo...' 'zorder': 0},' green': {'fc':' # D0F1BFF, 'ec':' # 2F3737, 'lw': 1,' zorder': 1}, 'forest': {' fc':'# 64B96A, 'ec':' # 2F37, 'lw': 1,' zorder': 1}, 'water': {' fc':'# a1e3fficient, 'ec':' # 2F3737' 'hatch':' ooo...', 'hatch_c':' # 85c9e6, 'lw': 1,' zorder': 2}, 'parking': {' fc':'# F2F4CB, 'ec':' # 2F3737, 'lw': 1,' zorder': 3}, 'streets': {' fc':'# 2F3713, 'ec':' # 475657, 'alpha': 1,' lw': 0 'zorder': 3},' building': {'palette': [' # FFC857','# E9724C','# C5283D'], 'ec':' # 2F37signals, 'lw':. 5,' zorder': 4},}, osm_credit = {'color':' # 2F37'}) # Export picture file plt.savefig ('Shanghai Bund-Circle Mode .png', dpi=500)
2.1.2 rounded rectangle mode
In addition to the circular mode mentioned above, the rounded rectangle mode can also be used in prettymaps. You also need to define the coordinate and radius of the center point, and then add a key value pair {'circle': False,' dilate': fillet radius} for each key-value pair under the parameter layers, where the fillet radius is numerical. This time, let's go to another place. Take the Imperial Palace as an example, the radius is 600m:
# create bed fig, ax = plt.subplots (figsize = (12,12), constrained_layout = True) dilate = 100layers = plot ((39.91645697864148,116.39077532493388), # Center coordinate, format: (latitude, longitude) radius = 600,# Radius ax = ax, # bind bed layers = {'perimeter': {' circle': False, 'dilate': dilate}, # control drawing mode {}, which is equivalent to circular drawing mode # the following parameters are used to define vector layer features obtained from OsmStreetMap selection If you don't know, you can copy 'streets': {' custom_filter':'["highway" ~ "motorway | trunk | primary | secondary | tertiary | residential | service | unclassified | pedestrian | footway"], 'width': {' motorway': 5, 'trunk': 5,' primary': 4.5, 'secondary': 4 'tertiary': 3,' residential': 3, 'service': 2,' unclassified': 2, 'pedestrian': 2,' footway': 1,}, 'circle': False,' dilate': dilate} 'building': {' tags': {'building': True,' landuse': 'construction'},' union': False, 'circle': False,' dilate': dilate}, 'water': {' tags': {'natural': [' water', 'bay']},' circle': False, 'dilate': dilate},' green': {'tags': {' landuse': 'grass' 'natural': [' island', 'wood'],' leisure': 'park'},' circle': False, 'dilate': dilate},' forest': {'tags': {' landuse': 'forest'},' circle': False, 'dilate': dilate},' parking': {'tags': {' amenity': 'parking',' highway': 'pedestrian',' man_made': 'pier'} The following parameters are used to define the styles of different vector layers in OpenStreetMap: 'circle': False,' dilate': dilate}}, # If you find it troublesome to copy the following official example directly, you can drawing_kwargs = {'background': {' fc':'# F2F4CBsituation, 'ec':' dadbc1', 'hatch':' ooo...', 'zorder':-1},' perimeter': {'fc':' # F2F4CBbath, 'ec':' # dadbc1', 'lw': 0,' hatch': 'ooo...' 'zorder': 0},' green': {'fc':' # D0F1BFF, 'ec':' # 2F3737, 'lw': 1,' zorder': 1}, 'forest': {' fc':'# 64B96A, 'ec':' # 2F37, 'lw': 1,' zorder': 1}, 'water': {' fc':'# a1e3fficient, 'ec':' # 2F3737' 'hatch':' ooo...', 'hatch_c':' # 85c9e6, 'lw': 1,' zorder': 2}, 'parking': {' fc':'# F2F4CB, 'ec':' # 2F3737, 'lw': 1,' zorder': 3}, 'streets': {' fc':'# 2F3713, 'ec':' # 475657, 'alpha': 1,' lw': 0 'zorder': 3},' building': {'palette': [' # FFC857','# E9724C','# C5283D'], 'ec':' # 2F37signals, 'lw':. 5,' zorder': 4},}, osm_credit = {'color':' # 2F37'}) # Export picture file plt.savefig ('Beijing Imperial Palace-rounded rectangle mode .png', dpi=500)
2.1.3 add text content
With such a beautiful and generous art map, we can also add annotation information to the map based on the custom font method in matplotlib. Still take the Shanghai Bund as an example, we use external calligraphy fonts to draw text label information in the center:
Import matplotlib.font_manager as fm# create bed fig, ax = plt.subplots (figsize = (12,12), constrained_layout = True) layers = plot ((31.23346, 121.492154), # center coordinates, format: (latitude, longitude) radius = 2500, # radius ax = ax, # bind bed layers = {'perimeter': {}, # controls drawing mode {}, which is equivalent to circular drawing mode # the following parameters are used to define vector layer features obtained from OsmStreetMap selection If you don't know, you can copy 'streets': {' custom_filter':'["highway" ~ "motorway | trunk | primary | secondary | tertiary | residential | service | unclassified | pedestrian | footway"], 'width': {' motorway': 5, 'trunk': 5,' primary': 4.5, 'secondary': 4 'tertiary': 3,' residential': 3, 'service': 2,' unclassified': 2, 'pedestrian': 2,' footway': 1,}}, 'building': {' tags': {'building': True,' landuse': 'construction'} 'union': False},' water': {'tags': {' natural': ['water',' bay']}, 'green': {' tags': {'landuse':' grass', 'natural': [' island', 'wood'],' leisure': 'park'}},' forest': {'tags': {' landuse': 'forest'}} 'parking': {' tags': {'amenity':' parking', 'highway':' pedestrian', 'man_made':' pier'}}, # the following parameters are used to define the styles of different vector layers in OpenStreetMap If you find it troublesome to copy the following official example directly, you can drawing_kwargs = {'background': {' fc':'# F2F4CBsituation, 'ec':' dadbc1', 'hatch':' ooo...', 'zorder':-1},' perimeter': {'fc':' # F2F4CBbath, 'ec':' # dadbc1', 'lw': 0,' hatch': 'ooo...' 'zorder': 0},' green': {'fc':' # D0F1BFF, 'ec':' # 2F3737, 'lw': 1,' zorder': 1}, 'forest': {' fc':'# 64B96A, 'ec':' # 2F37, 'lw': 1,' zorder': 1}, 'water': {' fc':'# a1e3fficient, 'ec':' # 2F3737' 'hatch':' ooo...', 'hatch_c':' # 85c9e6, 'lw': 1,' zorder': 2}, 'parking': {' fc':'# F2F4CB, 'ec':' # 2F3737, 'lw': 1,' zorder': 3}, 'streets': {' fc':'# 2F3713, 'ec':' # 475657, 'alpha': 1,' lw': 0 'zorder': 3},' building': {'palette': [' # FFC857','# E9724C','# C5283D'], 'ec':' # 2F3737, 'lw':. 5,' zorder': 4},}, osm_credit = {'color':' # 2F3700'}) # add text labels ax.text (0.5,0.5, 'Bund, Shanghai', zorder = 6 Ha='center', va='center', fontsize=120, fontproperties = fm.FontProperties (fname='FZZJ-HLYHXSJW.TTF'), transform=ax.transAxes) # Export picture file plt.savefig ('Shanghai Bund-add text markup .png', dpi=500)
You can find the latitude and longitude coordinates of your place of concern and draw various art maps as much as you can, such as the following landmarks:
The above is all the contents of the article "how to quickly draw poster-level maps with Python". 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.