Giter Club home page Giter Club logo

Comments (6)

QuLogic avatar QuLogic commented on June 3, 2024

Are you running in a notebook or a script? Please provide a complete example.

from cartopy.

habtie-phys avatar habtie-phys commented on June 3, 2024

thanks for the reply. I run the code from VScode Jupyter notebook.

Below is the complete code. The plot parameters can be obtained from the attached json file
plot_params.json
The figure I got after running the code is also attached here
resulting_fig

import json
from matplotlib import pyplot as plt
import cartopy.crs as ccrs

with open('plot_params.json', 'r') as f:
    plot_params = json.load(f)
# 
glon_e3d = plot_params['glon_e3d']
gclat_e3d = plot_params['gclat_e3d']
glon_test = plot_params['glon_test']
gclat_test = plot_params['gclat_test']
lon_secs = plot_params['lon_secs']
lat_secs = plot_params['lat_secs']
# 
proj = ccrs.LambertAzimuthalEqualArea(central_latitude = clat, central_longitude = clon)
fig,axes = plt.subplots(1,3, figsize=(10,10),subplot_kw={'projection':proj})
axs = axes.ravel()
# 
extent = [205, 225, 63, 69]
ax = axs[0]
ax.gridlines()
ax.set_extent(extent, crs=ccrs.PlateCarree())
ax.scatter(glon_e3d, gclat_e3d, transform = ccrs.Geodetic(), c = 'r', marker = '.', label = 'data points', s=10)
# 
ax = axs[1]
ax.gridlines()
ax.set_extent(extent, crs=ccrs.PlateCarree())
ax.scatter(glon_test, gclat_test, transform = ccrs.Geodetic(), c = 'r', marker = '.', label = 'data points', s=10)
# 
ax = axs[2]
ax.gridlines()
ax.set_extent(extent, crs=ccrs.PlateCarree())
ax.scatter(lon_secs, lat_secs, transform = ccrs.Geodetic(), c = 'r', marker = '.', label = 'data points', s=10)

plt.show()

when the number of axes in the subplots is 1, the figsize parameter affects the actual size of the figure without changing extent of the axis. However, this is not the case when the number of the axes is higher than 1. In addition despite the given width and heights of the fig are equal, the result figure doesn't show that.

from cartopy.

rcomer avatar rcomer commented on June 3, 2024

Cartopy's axes all have fixed aspect ratios so will not fill up the figure when arranged like this. The default backend used by Jupyter always resizes the figure to fit around the artists on it. I suspect you will see consistent behaviour if you do a more simple plot without Cartopy:

import matplotlib.pyplot as plt

fig, ax_arr = plt.subplots(1,3, figsize=(10,10))

for ax in ax_arr:
    ax.set_aspect('equal')

from cartopy.

habtie-phys avatar habtie-phys commented on June 3, 2024

thanks for the reply. you are right, I see the same issue with the above code. However, the figure behave as expected when I remove the ax.set_aspect('equal') line. I will leave the issue open in case some one suggests a general solution

from cartopy.

dopplershift avatar dopplershift commented on June 3, 2024

@habtie-phys Right, ax.set_aspect('equal') is equivalent to what every Cartopy-based plot is doing due to the nature of plotting on geographic projections.

There isn't a general solution to this problem currently given that Matplotlib doesn't have a dynamic layout engine for Axes. Instead Matplotlib provides various APIs for carving out rectangles from a figure, which Axes are then free to adjust within to suit their needs.

Closing since at best anything addressing this would have to happen in Matplotlib itself.

from cartopy.

habtie-phys avatar habtie-phys commented on June 3, 2024

@dopplershift thank you for the reply. Now I understand that this is not the right place for the issue to remain open.

from cartopy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.