Cartopy fancy box

2024/11/16 8:19:58

Hello I have been trying to plot data in a Orthographic projection. The data is plotted but I want the box to follow the data limits. Like in this example I am sharing form M_map[enter image description here

[1]1

Do you have any suggestion?

Answer

In the comments under the question, you have several links to the existing answers that match the question. So that, this question is likely a duplicate question. However, none of the answers offers the zebra-pattern border as shown in the sample plot.

I take this opportunity to offer a distinct answer that also plots the map border with zebra pattern line similar to the sample plot.

import cartopy.crs as ccrs
import cartopy
import matplotlib.pyplot as plt
import matplotlib.path as mpath
import matplotlib.patches as patches# The lat-long projection
noProj = ccrs.PlateCarree(central_longitude=0)
# The projection of the map:
myProj = ccrs.Orthographic(central_longitude=-25, central_latitude=58)
myProj._threshold = myProj._threshold/40.  #for higher precision plotfig = plt.figure(figsize=(8,12))
ax = fig.add_subplot(1, 1, 1, projection=myProj)# Zebra-border-line segments ...
#  four edges on separate lines of code
# 1: lower edge: Left - Right
# 2: Right edge: Bottom - Top
# 3: Upper edge: Right - Left
# 4: Left edge: Top - Bottom
[ax_hdl] = ax.plot([-45, -40, -35, -30, -25, -20, -15, -10, -5,-5,-5,-5,-5,-5,-10,-15,-20,-25,-30,-35,-40,-45,-45, -45, -45, -45, -45],[45, 45, 45, 45, 45, 45, 45, 45, 45,50, 55, 60, 65, 70,70,70,70,70,70,70,70,70,65, 60, 55, 50, 45 ],color='black', linewidth=0.5,transform=noProj)
tx_path = ax_hdl._get_transformed_path()
path_in_data_coords, _ = tx_path.get_transformed_path_and_affine()
polygon1s = mpath.Path( path_in_data_coords.vertices)
vcode = [1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1]  #Path-code
polygon1v = mpath.Path( path_in_data_coords.vertices, vcode)ax.set_boundary(polygon1s) #masks-out unwanted part of the plot# Zebra-pattern creation
# The pattern line is created from 2 layers
#  lower layer: thicker, black solid line
#  top layer: thinner, dashed white line
patch1s = patches.PathPatch(polygon1s, facecolor='none', ec="black", lw=7, zorder=100)
patch1v = patches.PathPatch(polygon1v, facecolor='none', ec="white", lw=6, zorder=101)
ax.add_patch(patch1s)
ax.add_patch(patch1v)ax.gridlines(draw_labels=True, x_inline=False, y_inline=False)
ax.add_feature(cartopy.feature.OCEAN, linewidth=.3, color='lightblue')
ax.add_feature(cartopy.feature.LAND, zorder=1, edgecolor='black')
ax.title.set_text("Map with zebra border line")
plt.show()

zebra-border

https://en.xdnf.cn/q/119550.html

Related Q&A

discord.py - No DM sent to the user

I am making a discord.Client. I have a DM command that sends a DM to a specific user, but no message is sent to the user when the command is run, but a message is sent on the Context.channel. Here is m…

Improve CPU time of conditional statement

I have written an if-elif statement, which I believe not be very efficient:first_number = 1000 second_number = 700 switch = {upperRight: False,upperLeft: False,lowerRight: False,lowerLeft: False,middle…

Why no colon in forming a list from loop in one line in Python?

From this website, there is a way to form a list in Python from loop in one line squares = [i**2 for i in range(10)]My question is, typically, after a loop, there is a colon, e.g., squares = [] for i i…

Merge each groups rows into one row

Im experienced with Pandas but stumbled upon a problem that I cant seem to figure out. I have a large dataset ((40,000, 16)) and I am trying to group it by a specific column ("group_name" for…

Python decode unknown character

Im trying to decode the following: UKLTD� For into utf-8 (or anything really) but I cannot workout how to do it and keep getting errors likeascii codec cant decode byte 0xae in position 8: ordinal not…

UnboundLocalError: TRY EXCEPT STATEMENTS

I am currently creating a menu with try except tools. Im trying to create it so if a user enters nothing (presses ENTER) to output:You have not entered anything, please enter a number between 1 and 4Th…

Cant load music into pygame

please help if you can. Cant seem to be able to upload music into my game in progress. It comes up with the error of "cant load"... Would be great if someone got back to me quick, This is a m…

C# Socket: how to keep it open?

I am creating a simple server (C#) and client (python) that communicate using sockets. The server create a var listener = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp)then …

Python Selenium - how to get confirmation after submit

I have a follow up question on this post, I want to get any confirmation text after I hit submit button. Either the code works or not. html - invalid example <div class="serialModalArea js-seri…

Assigning a input on a line to its line number?

I was having a go at the following problem from the AIO (Australian Informatics Olympiad) Training Problems Site (Question in Italics and specifics in bold, my attempt below): The Problem Encyclopaedia…