Free AI web copilot to create summaries, insights and extended knowledge, download it at here
3969
Abstract
lors, and no axes by default, streamlining the process of plotting vector data. If needed, you can easily customize the appearance using gspatial_plot, Geopandas, or Matplotlib parameters.</p><div id="7f83"><pre>gsp<span class="hljs-selector-class">.shapeplot</span>(usa, figsize=(<span class="hljs-number">15</span>, <span class="hljs-number">15</span>))</pre></div><figure id="5a4f"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*hgepISp4blKLRyoMFCcqAg.png"><figcaption></figcaption></figure><p id="970d">You also have the option to adjust the parameters according to your needs. For instance, let’s incorporate a title into the visualization:</p><div id="b7f0"><pre>gsp.shapeplot(
usa,
title=<span class="hljs-string">"USA MAP"</span>,
title_kwds={<span class="hljs-string">"fontsize"</span>: 25, <span class="hljs-string">"fontname"</span>: <span class="hljs-string">"sans-serif"</span>, <span class="hljs-string">"fontweight"</span>: 3},
)</pre></div><figure id="4438"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*mIWUUXOP3u1uiZXQs_N2Lg.png"><figcaption></figcaption></figure><p id="1dc8"><b>Here’s the explanation of the shapeplot function’s parameters:</b></p><p id="7d22">• data (GeoDataFrame): GeoDataFrame used as the data source for the map.
• title (str): Title displayed on the map. Default is None.
• title_kwds (dict): Keyword arguments for configuring title appearance using matplotlib.pyplot.title. Default is an empty dictionary.
• figsize (tuple): Dimensions of the figure. Default is (15, 15).
• facecolor (str): Background color of the figure. Default is “white”.
• edgecolor (str): Color of the map’s edges. Default is “black”.
• linewidth (float): Line width for shapes. Default is 0.5.
• color (str): Color of the shape. Default is “#F1F3F4”.
• annot (bool): Toggle annotations on/off. Default is False.
• annot_column (str/GeoDataFrame column): Source column for annotations. Default is None.
• annot_align (str): Text alignment for annotations. Default is “center”.
• annot_kwds (dict): Keyword arguments for customizing annotations. Default is an empty dictionary.
• ax (matplotlib axis): Existing axis for plotting, if needed. Default is None.
• axis_on (bool): Toggle axis visibility. Default is False.
• **geopandas_plot_kwds: Additional keyword arguments for Geopandas plot customization.</p><p id="5a62">Returns: Matplotlib axis object (ax) representing the map.</p><p id="39a4">This function enables straightforward GeoDataFrame shape plotting with customizable options for appearance and annotations, while allowing flexibility in using existing axes for plotting. The function returns a matplotlib axis object representing the generated map.</p><h1 id="7308">pointplot</h1><p id="e010">Point plot is designed specifically for visualizing point data. A key distinction between point plot and shapeplot lies in the ability to utilize a base vector layer of shapes. This base layer allows points to be plotted on top, enabling a layered representation.</p><div id="62be"><pre>usa_points = usa.representative_point()
gsp.pointplot(usa_points, <span class="hljs-keyword">base</span>=usa)</pre></div><figure id="e5d7"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*ZOiYi_T2DL9CU9Kx7-KpGA.png"><figcaption></figcaption></figure><p id="6b86">Alternatively, you have the option to plot the polygons themselves instead of just their boundaries in the base layer.</p><div id="aac0"><pre>gsp.pointplot(usa_points, <span class="hljs-keyword">base</span>=usa, base_boundary=False)</pre></div><figure id="3412"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*_Sz_IGkazfobhvTpV3Y8Ag.png"><figcaption></figcaption></figure><p id="8f2e">Points can be plotted independently, without the need for a base layer.</p><div id="30aa"><pre>gsp<span class="hljs-selector-class">.pointplot</span>(usa_points)</pre></div><figure id="d8ed"><img src="https://cdn
Options
-images-1.readmedium.com/v2/resize:fit:800/1*zFOL9eUsmS-5S67MeufNcQ.png"><figcaption></figcaption></figure><p id="5c42">Matplotlib axis objects offer the ability to merge and combine multiple plots.</p><div id="4753"><pre>ax = gsp.shapeplot(usa, figsize=(<span class="hljs-number">15</span>, <span class="hljs-number">15</span>))
gsp.pointplot(usa_points, ax=ax)</pre></div><figure id="f05f"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*_Sz_IGkazfobhvTpV3Y8Ag.png"><figcaption></figcaption></figure><p id="b9e0">It’s also possible to tailor the appearance of the base layer according to your preferences.</p><div id="3dfa"><pre>gsp.pointplot(
usa_points,
base=usa,
basecolor=<span class="hljs-string">"#7aebff"</span>,
base_boundary=<span class="hljs-literal">False</span>,
title=<span class="hljs-string">"USA Points"</span>,
title_kwds={<span class="hljs-string">"fontsize"</span>: <span class="hljs-number">25</span>, <span class="hljs-string">"fontname"</span>: <span class="hljs-string">"sans-serif"</span>, <span class="hljs-string">"fontweight"</span>: <span class="hljs-number">3</span>},
)</pre></div><figure id="ce5a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*AiPv5roDBIrvCc92oIvZ4g.png"><figcaption></figcaption></figure><p id="3d19"><b>Here’s the breakdown of the pointplot function’s parameters:</b></p><p id="a875">• data (GeoDataFrame): The GeoDataFrame used for plotting the map.
• base (GeoDataFrame): Base GeoDataFrame on top of which the data will be plotted. Defaults to None.
• title (str): Title of the map. Defaults to None.
• title_kwds (dict): Keyword arguments for configuring the appearance of the title using matplotlib.pyplot.title. Defaults to an empty dictionary.
• figsize (tuple): Size of the figure. Defaults to (15, 15).
• color (str): Color of the point. Defaults to “#ffb536”.
• edgecolor (str): Color of the map’s edges. Defaults to “black”.
• basecolor (str): Color of the base data. Defaults to “#F1F3F4”.
• baseboundarycolor (str): Boundary color of the base data. Defaults to “black”.
• base_boundary (bool): Toggle visibility of base data boundaries. Defaults to True.
• boundary_linewidth (float): Linewidth of the base data boundaries. Defaults to 0.5.
• linewidth (float): Width of lines for shapes. Defaults to 0.5.
• annot (bool): If True, annotations are generated. Defaults to False.
• annot_column (str/GeoDataFrame column): If annot is True, column should be passed as the source for annotation. Defaults to None.
• annot_align (str): Text alignment for annotations. Defaults to “center”.
• annot_kwds (dict): Keyword arguments for annotation customization. Defaults to an empty dictionary.
• ax (matplotlib axis): Existing axis for plotting. Defaults to None.
• axis_on (bool): Toggle axis visibility. Defaults to False.
• facecolor (str): Figure’s face color. Defaults to “white”.
• **geopandas_plot_kwds: Additional Geopandas plot keyword arguments.</p><p id="fd44">Returns: Matplotlib axis object (ax).</p><h1 id="44de">Tips for Polished Maps</h1><p id="46bb"><b>Harmonious Color Choices:</b>
Experiment with color palettes to create maps that are visually pleasing and easy to understand. Choose colors that enhance the readability of your map.</p><p id="6be4"><b>Precise Annotations:</b>
Annotations provide context to your maps. Customize annotation alignment and appearance to guide viewers through your spatial narrative seamlessly.</p><p id="b235"><b>Seamless Matplotlib Integration:</b>
Leverage the integration with Matplotlib to fine-tune your maps’ aesthetics, titles, and labels for a polished final product.</p><h1 id="071e">Conclusion</h1><p id="3df6">In this tutorial, we’ve covered the essentials of crafting geospatial maps using the gspatial_plot library. With gspatial_plot, the process of geospatial mapping becomes more manageable and easy. See you in the next tutorial— happy mapping!</p></article></body>