I am trying to control the labels on my plot with LambertConformal projection
Some exsted discussion provide how to plot it on a rectangular box .
Cartopy: axis label – workaround
However, I want to have my chart with conical box and found
1, there might be some labels on the top of my charts ( 50N in my result.png attached generated in Google Colab, but it may show more labels if iI change the font size.)
2. If i want to show the labels with some specific value. the grindline would also be compromised as i use gridlines function to drawing the line and label at the same time.
How can I to control the labels in a systematic way in order to cater changes of omitting some values/extending the plotting area. ?Thanks
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import matplotlib.ticker as mticker
import matplotlib.path as mpath
# Create a figure and an axis with the Lambert Conformal projection
fig = plt.figure(figsize=(10, 5))
ax_map = fig.add_subplot(1, 1, 1,
projection=ccrs.LambertConformal(
central_longitude=100,
central_latitude=80,
standard_parallels=(60, 80)))
# Draw coastlines and set extent
extent = [40, 160, -0.1, 80.1]
ax_map.set_extent(extent, crs=ccrs.PlateCarree())
# Define the rectangle boundary
rect = mpath.Path([
[extent[0], extent[2]],
[extent[0], extent[3]],
[extent[1], extent[3]],
[extent[1], extent[2]],
[extent[0], extent[2]]
]).interpolated(20)
ax_map.set_boundary(rect, transform=ccrs.PlateCarree())
# Define tick values for x and y axes
x_tick_value = [40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]
y_tick_value = [0, 10, 20, 30, 40, 50, 60, 70, 80]
# Create gridlines
gl = ax_map.gridlines(draw_labels=True, x_inline=False, y_inline=False, crs=ccrs.PlateCarree())
gl.xlocator = mticker.FixedLocator(x_tick_value)
gl.ylocator = mticker.FixedLocator(y_tick_value)
gl.xlabel_style = {'rotation': 0, 'ha': 'center'} # Rotate labels
# Show the plot
plt.show()
Sample Generated by Colab
user27162955 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.