embed small map (cartopy) on matplotlib figureHow do you change the size of figures drawn with matplotlib?In Matplotlib, what does the argument mean in fig.add_subplot(111)?setting y-axis limit in matplotlibHow to change the font size on a matplotlib plotSave plot to image file instead of displaying it using MatplotlibHow do I set the figure title and axes labels font size in Matplotlib?Changing the “tick frequency” on x or y axis in matplotlib?How to make IPython notebook matplotlib plot inlineInstallation Issue with matplotlib PythonCartopy (or is it Matplotlib?) incorrectly plotting points in an upward curve from 0,0
Why does Windows store Wi-Fi passwords in a reversible format?
Was the Boeing 2707 design flawed?
Why does matter stays collapsed following the supernova explosion?
How to sort a dictionary of lists and get the corresponding keys?
Can you board the plane when your passport is valid less than 3 months?
Discussing work with supervisor in an invited dinner with his family
How to prevent a hosting company from accessing a VM's encryption keys?
Can I get a PhD for developing an educational software?
How to use properly "sich selbst"
What is the name of this plot that has rows with two connected dots?
Did anybody find out it was Anakin who blew up the command center?
rationalizing sieges in a modern/near-future setting
Can MuseScore be used programmatically?
Thought experiment and possible contradiction between electromagnetism and special relativity
How many lines of code does the original TeX contain?
Cost of oil sanctions to world's consumers
Hangman game in Python - need feedback on the quality of code
Location of label edges in Tikz Graph
Unlock your Lock
Open subspaces of CW complexes
What does it take for witness testimony to be believed?
Count the number of paths to n
Why is adding AC power easier than adding DC power?
Why is a statement like 1 + n *= 3 allowed in Ruby?
embed small map (cartopy) on matplotlib figure
How do you change the size of figures drawn with matplotlib?In Matplotlib, what does the argument mean in fig.add_subplot(111)?setting y-axis limit in matplotlibHow to change the font size on a matplotlib plotSave plot to image file instead of displaying it using MatplotlibHow do I set the figure title and axes labels font size in Matplotlib?Changing the “tick frequency” on x or y axis in matplotlib?How to make IPython notebook matplotlib plot inlineInstallation Issue with matplotlib PythonCartopy (or is it Matplotlib?) incorrectly plotting points in an upward curve from 0,0
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
# imports
from collections import namedtuple
import numpy as np
import xarray as xr
import shapely
import cartopy
The data that I have looks like this.
I have a region of interest (defined here as all_region
). I have an xr.DataArray
which contains my variable.
What I want to do it to select one PIXEL (lat,lon pair) and to plot a small map in the corner of the lineplot showing here that pixel is located.
Region = namedtuple('Region',field_names=['region_name','lonmin','lonmax','latmin','latmax'])
all_region = Region(
region_name="all_region",
lonmin = 32.6,
lonmax = 51.8,
latmin = -5.0,
latmax = 15.2,
)
data = np.random.normal(0,1,(12, 414, 395))
lats = np.linspace(-4.909738, 15.155708, 414)
lons = np.linspace(32.605801, 51.794488, 395)
months = np.arange(1,13)
da = xr.DataArray(data, coords=[months, lats, lons], dims=['month','lat','lon'])
These are the functions that I need to fix to work with inset axes.
I have these functions which plot my timeseries from the xarray object, and also the location of the lat,lon point.
def plot_location(region):
""" use cartopy to plot the region (defined as a namedtuple object)
"""
lonmin,lonmax,latmin,latmax = region.lonmin,region.lonmax,region.latmin,region.latmax
fig = plt.figure()
ax = fig.gca(projection=cartopy.crs.PlateCarree())
ax.add_feature(cartopy.feature.COASTLINE)
ax.add_feature(cartopy.feature.BORDERS, linestyle=':')
ax.set_extent([lonmin, lonmax, latmin, latmax])
return fig, ax
def select_pixel(ds, loc):
""" (lat,lon) """
return ds.sel(lat=loc[1],lon=loc[0],method='nearest')
def turn_tuple_to_point(loc):
""" (lat,lon) """
from shapely.geometry.point import Point
point = Point(loc[1], loc[0])
return point
def add_point_location_to_map(point, ax, color=(0,0,0,1), **kwargs):
""" """
ax.scatter(point.x,
point.y,
transform=cartopy.crs.PlateCarree(),
c=[color],
**kwargs)
return
Here I do the plotting
# choose a lat lon location that want to plot
loc = (2.407,38.1)
# 1. plot the TIME SERIES FOR THE POINT
fig,ax = plt.subplots()
pixel_da = select_pixel(da, loc)
pixel_da.plot.line(ax=ax, marker='o')
# 2. plot the LOCATION for the point
fig,ax = plot_location(all_region)
point = turn_tuple_to_point(loc)
add_point_location_to_map(point, ax)
I have my function for plotting a region, but I want to put this on an axis in the corner of my figure! Like this:
How would I go about doing this? I have had a look at the inset_locator
method but as far as I can tell the mpl_toolkits.axes_grid1.parasite_axes.AxesHostAxes
has no means of assigning a projection, which is required for cartopy.
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
proj=cartopy.crs.PlateCarree
axins = inset_axes(ax, width="20%", height="20%", loc=2, projection=proj)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-162-9b5fd4f34c3e> in <module>
----> 1 axins = inset_axes(ax, width="20%", height="20%", loc=2, projection=proj)
TypeError: inset_axes() got an unexpected keyword argument 'projection'
python python-3.x matplotlib cartopy
add a comment |
# imports
from collections import namedtuple
import numpy as np
import xarray as xr
import shapely
import cartopy
The data that I have looks like this.
I have a region of interest (defined here as all_region
). I have an xr.DataArray
which contains my variable.
What I want to do it to select one PIXEL (lat,lon pair) and to plot a small map in the corner of the lineplot showing here that pixel is located.
Region = namedtuple('Region',field_names=['region_name','lonmin','lonmax','latmin','latmax'])
all_region = Region(
region_name="all_region",
lonmin = 32.6,
lonmax = 51.8,
latmin = -5.0,
latmax = 15.2,
)
data = np.random.normal(0,1,(12, 414, 395))
lats = np.linspace(-4.909738, 15.155708, 414)
lons = np.linspace(32.605801, 51.794488, 395)
months = np.arange(1,13)
da = xr.DataArray(data, coords=[months, lats, lons], dims=['month','lat','lon'])
These are the functions that I need to fix to work with inset axes.
I have these functions which plot my timeseries from the xarray object, and also the location of the lat,lon point.
def plot_location(region):
""" use cartopy to plot the region (defined as a namedtuple object)
"""
lonmin,lonmax,latmin,latmax = region.lonmin,region.lonmax,region.latmin,region.latmax
fig = plt.figure()
ax = fig.gca(projection=cartopy.crs.PlateCarree())
ax.add_feature(cartopy.feature.COASTLINE)
ax.add_feature(cartopy.feature.BORDERS, linestyle=':')
ax.set_extent([lonmin, lonmax, latmin, latmax])
return fig, ax
def select_pixel(ds, loc):
""" (lat,lon) """
return ds.sel(lat=loc[1],lon=loc[0],method='nearest')
def turn_tuple_to_point(loc):
""" (lat,lon) """
from shapely.geometry.point import Point
point = Point(loc[1], loc[0])
return point
def add_point_location_to_map(point, ax, color=(0,0,0,1), **kwargs):
""" """
ax.scatter(point.x,
point.y,
transform=cartopy.crs.PlateCarree(),
c=[color],
**kwargs)
return
Here I do the plotting
# choose a lat lon location that want to plot
loc = (2.407,38.1)
# 1. plot the TIME SERIES FOR THE POINT
fig,ax = plt.subplots()
pixel_da = select_pixel(da, loc)
pixel_da.plot.line(ax=ax, marker='o')
# 2. plot the LOCATION for the point
fig,ax = plot_location(all_region)
point = turn_tuple_to_point(loc)
add_point_location_to_map(point, ax)
I have my function for plotting a region, but I want to put this on an axis in the corner of my figure! Like this:
How would I go about doing this? I have had a look at the inset_locator
method but as far as I can tell the mpl_toolkits.axes_grid1.parasite_axes.AxesHostAxes
has no means of assigning a projection, which is required for cartopy.
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
proj=cartopy.crs.PlateCarree
axins = inset_axes(ax, width="20%", height="20%", loc=2, projection=proj)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-162-9b5fd4f34c3e> in <module>
----> 1 axins = inset_axes(ax, width="20%", height="20%", loc=2, projection=proj)
TypeError: inset_axes() got an unexpected keyword argument 'projection'
python python-3.x matplotlib cartopy
add a comment |
# imports
from collections import namedtuple
import numpy as np
import xarray as xr
import shapely
import cartopy
The data that I have looks like this.
I have a region of interest (defined here as all_region
). I have an xr.DataArray
which contains my variable.
What I want to do it to select one PIXEL (lat,lon pair) and to plot a small map in the corner of the lineplot showing here that pixel is located.
Region = namedtuple('Region',field_names=['region_name','lonmin','lonmax','latmin','latmax'])
all_region = Region(
region_name="all_region",
lonmin = 32.6,
lonmax = 51.8,
latmin = -5.0,
latmax = 15.2,
)
data = np.random.normal(0,1,(12, 414, 395))
lats = np.linspace(-4.909738, 15.155708, 414)
lons = np.linspace(32.605801, 51.794488, 395)
months = np.arange(1,13)
da = xr.DataArray(data, coords=[months, lats, lons], dims=['month','lat','lon'])
These are the functions that I need to fix to work with inset axes.
I have these functions which plot my timeseries from the xarray object, and also the location of the lat,lon point.
def plot_location(region):
""" use cartopy to plot the region (defined as a namedtuple object)
"""
lonmin,lonmax,latmin,latmax = region.lonmin,region.lonmax,region.latmin,region.latmax
fig = plt.figure()
ax = fig.gca(projection=cartopy.crs.PlateCarree())
ax.add_feature(cartopy.feature.COASTLINE)
ax.add_feature(cartopy.feature.BORDERS, linestyle=':')
ax.set_extent([lonmin, lonmax, latmin, latmax])
return fig, ax
def select_pixel(ds, loc):
""" (lat,lon) """
return ds.sel(lat=loc[1],lon=loc[0],method='nearest')
def turn_tuple_to_point(loc):
""" (lat,lon) """
from shapely.geometry.point import Point
point = Point(loc[1], loc[0])
return point
def add_point_location_to_map(point, ax, color=(0,0,0,1), **kwargs):
""" """
ax.scatter(point.x,
point.y,
transform=cartopy.crs.PlateCarree(),
c=[color],
**kwargs)
return
Here I do the plotting
# choose a lat lon location that want to plot
loc = (2.407,38.1)
# 1. plot the TIME SERIES FOR THE POINT
fig,ax = plt.subplots()
pixel_da = select_pixel(da, loc)
pixel_da.plot.line(ax=ax, marker='o')
# 2. plot the LOCATION for the point
fig,ax = plot_location(all_region)
point = turn_tuple_to_point(loc)
add_point_location_to_map(point, ax)
I have my function for plotting a region, but I want to put this on an axis in the corner of my figure! Like this:
How would I go about doing this? I have had a look at the inset_locator
method but as far as I can tell the mpl_toolkits.axes_grid1.parasite_axes.AxesHostAxes
has no means of assigning a projection, which is required for cartopy.
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
proj=cartopy.crs.PlateCarree
axins = inset_axes(ax, width="20%", height="20%", loc=2, projection=proj)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-162-9b5fd4f34c3e> in <module>
----> 1 axins = inset_axes(ax, width="20%", height="20%", loc=2, projection=proj)
TypeError: inset_axes() got an unexpected keyword argument 'projection'
python python-3.x matplotlib cartopy
# imports
from collections import namedtuple
import numpy as np
import xarray as xr
import shapely
import cartopy
The data that I have looks like this.
I have a region of interest (defined here as all_region
). I have an xr.DataArray
which contains my variable.
What I want to do it to select one PIXEL (lat,lon pair) and to plot a small map in the corner of the lineplot showing here that pixel is located.
Region = namedtuple('Region',field_names=['region_name','lonmin','lonmax','latmin','latmax'])
all_region = Region(
region_name="all_region",
lonmin = 32.6,
lonmax = 51.8,
latmin = -5.0,
latmax = 15.2,
)
data = np.random.normal(0,1,(12, 414, 395))
lats = np.linspace(-4.909738, 15.155708, 414)
lons = np.linspace(32.605801, 51.794488, 395)
months = np.arange(1,13)
da = xr.DataArray(data, coords=[months, lats, lons], dims=['month','lat','lon'])
These are the functions that I need to fix to work with inset axes.
I have these functions which plot my timeseries from the xarray object, and also the location of the lat,lon point.
def plot_location(region):
""" use cartopy to plot the region (defined as a namedtuple object)
"""
lonmin,lonmax,latmin,latmax = region.lonmin,region.lonmax,region.latmin,region.latmax
fig = plt.figure()
ax = fig.gca(projection=cartopy.crs.PlateCarree())
ax.add_feature(cartopy.feature.COASTLINE)
ax.add_feature(cartopy.feature.BORDERS, linestyle=':')
ax.set_extent([lonmin, lonmax, latmin, latmax])
return fig, ax
def select_pixel(ds, loc):
""" (lat,lon) """
return ds.sel(lat=loc[1],lon=loc[0],method='nearest')
def turn_tuple_to_point(loc):
""" (lat,lon) """
from shapely.geometry.point import Point
point = Point(loc[1], loc[0])
return point
def add_point_location_to_map(point, ax, color=(0,0,0,1), **kwargs):
""" """
ax.scatter(point.x,
point.y,
transform=cartopy.crs.PlateCarree(),
c=[color],
**kwargs)
return
Here I do the plotting
# choose a lat lon location that want to plot
loc = (2.407,38.1)
# 1. plot the TIME SERIES FOR THE POINT
fig,ax = plt.subplots()
pixel_da = select_pixel(da, loc)
pixel_da.plot.line(ax=ax, marker='o')
# 2. plot the LOCATION for the point
fig,ax = plot_location(all_region)
point = turn_tuple_to_point(loc)
add_point_location_to_map(point, ax)
I have my function for plotting a region, but I want to put this on an axis in the corner of my figure! Like this:
How would I go about doing this? I have had a look at the inset_locator
method but as far as I can tell the mpl_toolkits.axes_grid1.parasite_axes.AxesHostAxes
has no means of assigning a projection, which is required for cartopy.
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
proj=cartopy.crs.PlateCarree
axins = inset_axes(ax, width="20%", height="20%", loc=2, projection=proj)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-162-9b5fd4f34c3e> in <module>
----> 1 axins = inset_axes(ax, width="20%", height="20%", loc=2, projection=proj)
TypeError: inset_axes() got an unexpected keyword argument 'projection'
python python-3.x matplotlib cartopy
python python-3.x matplotlib cartopy
asked Mar 27 at 19:58
Tommy LeesTommy Lees
3611 silver badge14 bronze badges
3611 silver badge14 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The mpl_toolkits.axes_grid1.inset_locator.inset_axes
does not have a projection
keyword. It only provides an axes_class
argument. Now one might be tempted to provide the cartopy.mpl.geoaxes.GeoAxes
directly to that argument, yet this would be missing the actual projection in use. So in addition one needs to set the projection via the axes_kwargs
argument.
inset_axes(..., axes_class=cartopy.mpl.geoaxes.GeoAxes,
axes_kwargs=dict(map_projection=cartopy.crs.PlateCarree()))
Complete example:
import cartopy
import cartopy.mpl.geoaxes
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
fig, ax = plt.subplots()
ax.plot([4,5,3,1,2])
axins = inset_axes(ax, width="40%", height="40%", loc="upper right",
axes_class=cartopy.mpl.geoaxes.GeoAxes,
axes_kwargs=dict(map_projection=cartopy.crs.PlateCarree()))
axins.add_feature(cartopy.feature.COASTLINE)
plt.show()
thank you very much! just having a quick play with both answers now
– Tommy Lees
Mar 27 at 22:40
This worked an absolute treat thankyou!!
– Tommy Lees
Mar 30 at 21:49
add a comment |
I don't have cartopy
installed to test it directly, but I believe you can circumvent the problem by creating your inset Axes by hand directly, using fig.add_axes()
. If you want to specify its position relative to the main axes, you can easily calculate the rect
parameter using the info returned by the main axes get_position()
.
For example:
pad = 0.05
w = 0.4
h = 0.25
fig, ax = plt.subplots()
a = ax.get_position()
ax2 = fig.add_axes([a.x1-(w+pad)*a.width,a.y1-(h+pad)*a.height,w*a.width,h*a.height], projection="hammer")
thank you so much! just having an experiment with both answers now
– Tommy Lees
Mar 27 at 22:39
This also works! I don't quite know how which to select but both are great answers!
– Tommy Lees
Mar 30 at 22:00
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55385515%2fembed-small-map-cartopy-on-matplotlib-figure%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The mpl_toolkits.axes_grid1.inset_locator.inset_axes
does not have a projection
keyword. It only provides an axes_class
argument. Now one might be tempted to provide the cartopy.mpl.geoaxes.GeoAxes
directly to that argument, yet this would be missing the actual projection in use. So in addition one needs to set the projection via the axes_kwargs
argument.
inset_axes(..., axes_class=cartopy.mpl.geoaxes.GeoAxes,
axes_kwargs=dict(map_projection=cartopy.crs.PlateCarree()))
Complete example:
import cartopy
import cartopy.mpl.geoaxes
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
fig, ax = plt.subplots()
ax.plot([4,5,3,1,2])
axins = inset_axes(ax, width="40%", height="40%", loc="upper right",
axes_class=cartopy.mpl.geoaxes.GeoAxes,
axes_kwargs=dict(map_projection=cartopy.crs.PlateCarree()))
axins.add_feature(cartopy.feature.COASTLINE)
plt.show()
thank you very much! just having a quick play with both answers now
– Tommy Lees
Mar 27 at 22:40
This worked an absolute treat thankyou!!
– Tommy Lees
Mar 30 at 21:49
add a comment |
The mpl_toolkits.axes_grid1.inset_locator.inset_axes
does not have a projection
keyword. It only provides an axes_class
argument. Now one might be tempted to provide the cartopy.mpl.geoaxes.GeoAxes
directly to that argument, yet this would be missing the actual projection in use. So in addition one needs to set the projection via the axes_kwargs
argument.
inset_axes(..., axes_class=cartopy.mpl.geoaxes.GeoAxes,
axes_kwargs=dict(map_projection=cartopy.crs.PlateCarree()))
Complete example:
import cartopy
import cartopy.mpl.geoaxes
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
fig, ax = plt.subplots()
ax.plot([4,5,3,1,2])
axins = inset_axes(ax, width="40%", height="40%", loc="upper right",
axes_class=cartopy.mpl.geoaxes.GeoAxes,
axes_kwargs=dict(map_projection=cartopy.crs.PlateCarree()))
axins.add_feature(cartopy.feature.COASTLINE)
plt.show()
thank you very much! just having a quick play with both answers now
– Tommy Lees
Mar 27 at 22:40
This worked an absolute treat thankyou!!
– Tommy Lees
Mar 30 at 21:49
add a comment |
The mpl_toolkits.axes_grid1.inset_locator.inset_axes
does not have a projection
keyword. It only provides an axes_class
argument. Now one might be tempted to provide the cartopy.mpl.geoaxes.GeoAxes
directly to that argument, yet this would be missing the actual projection in use. So in addition one needs to set the projection via the axes_kwargs
argument.
inset_axes(..., axes_class=cartopy.mpl.geoaxes.GeoAxes,
axes_kwargs=dict(map_projection=cartopy.crs.PlateCarree()))
Complete example:
import cartopy
import cartopy.mpl.geoaxes
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
fig, ax = plt.subplots()
ax.plot([4,5,3,1,2])
axins = inset_axes(ax, width="40%", height="40%", loc="upper right",
axes_class=cartopy.mpl.geoaxes.GeoAxes,
axes_kwargs=dict(map_projection=cartopy.crs.PlateCarree()))
axins.add_feature(cartopy.feature.COASTLINE)
plt.show()
The mpl_toolkits.axes_grid1.inset_locator.inset_axes
does not have a projection
keyword. It only provides an axes_class
argument. Now one might be tempted to provide the cartopy.mpl.geoaxes.GeoAxes
directly to that argument, yet this would be missing the actual projection in use. So in addition one needs to set the projection via the axes_kwargs
argument.
inset_axes(..., axes_class=cartopy.mpl.geoaxes.GeoAxes,
axes_kwargs=dict(map_projection=cartopy.crs.PlateCarree()))
Complete example:
import cartopy
import cartopy.mpl.geoaxes
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
fig, ax = plt.subplots()
ax.plot([4,5,3,1,2])
axins = inset_axes(ax, width="40%", height="40%", loc="upper right",
axes_class=cartopy.mpl.geoaxes.GeoAxes,
axes_kwargs=dict(map_projection=cartopy.crs.PlateCarree()))
axins.add_feature(cartopy.feature.COASTLINE)
plt.show()
edited Mar 27 at 22:03
answered Mar 27 at 21:48
ImportanceOfBeingErnestImportanceOfBeingErnest
163k16 gold badges204 silver badges298 bronze badges
163k16 gold badges204 silver badges298 bronze badges
thank you very much! just having a quick play with both answers now
– Tommy Lees
Mar 27 at 22:40
This worked an absolute treat thankyou!!
– Tommy Lees
Mar 30 at 21:49
add a comment |
thank you very much! just having a quick play with both answers now
– Tommy Lees
Mar 27 at 22:40
This worked an absolute treat thankyou!!
– Tommy Lees
Mar 30 at 21:49
thank you very much! just having a quick play with both answers now
– Tommy Lees
Mar 27 at 22:40
thank you very much! just having a quick play with both answers now
– Tommy Lees
Mar 27 at 22:40
This worked an absolute treat thankyou!!
– Tommy Lees
Mar 30 at 21:49
This worked an absolute treat thankyou!!
– Tommy Lees
Mar 30 at 21:49
add a comment |
I don't have cartopy
installed to test it directly, but I believe you can circumvent the problem by creating your inset Axes by hand directly, using fig.add_axes()
. If you want to specify its position relative to the main axes, you can easily calculate the rect
parameter using the info returned by the main axes get_position()
.
For example:
pad = 0.05
w = 0.4
h = 0.25
fig, ax = plt.subplots()
a = ax.get_position()
ax2 = fig.add_axes([a.x1-(w+pad)*a.width,a.y1-(h+pad)*a.height,w*a.width,h*a.height], projection="hammer")
thank you so much! just having an experiment with both answers now
– Tommy Lees
Mar 27 at 22:39
This also works! I don't quite know how which to select but both are great answers!
– Tommy Lees
Mar 30 at 22:00
add a comment |
I don't have cartopy
installed to test it directly, but I believe you can circumvent the problem by creating your inset Axes by hand directly, using fig.add_axes()
. If you want to specify its position relative to the main axes, you can easily calculate the rect
parameter using the info returned by the main axes get_position()
.
For example:
pad = 0.05
w = 0.4
h = 0.25
fig, ax = plt.subplots()
a = ax.get_position()
ax2 = fig.add_axes([a.x1-(w+pad)*a.width,a.y1-(h+pad)*a.height,w*a.width,h*a.height], projection="hammer")
thank you so much! just having an experiment with both answers now
– Tommy Lees
Mar 27 at 22:39
This also works! I don't quite know how which to select but both are great answers!
– Tommy Lees
Mar 30 at 22:00
add a comment |
I don't have cartopy
installed to test it directly, but I believe you can circumvent the problem by creating your inset Axes by hand directly, using fig.add_axes()
. If you want to specify its position relative to the main axes, you can easily calculate the rect
parameter using the info returned by the main axes get_position()
.
For example:
pad = 0.05
w = 0.4
h = 0.25
fig, ax = plt.subplots()
a = ax.get_position()
ax2 = fig.add_axes([a.x1-(w+pad)*a.width,a.y1-(h+pad)*a.height,w*a.width,h*a.height], projection="hammer")
I don't have cartopy
installed to test it directly, but I believe you can circumvent the problem by creating your inset Axes by hand directly, using fig.add_axes()
. If you want to specify its position relative to the main axes, you can easily calculate the rect
parameter using the info returned by the main axes get_position()
.
For example:
pad = 0.05
w = 0.4
h = 0.25
fig, ax = plt.subplots()
a = ax.get_position()
ax2 = fig.add_axes([a.x1-(w+pad)*a.width,a.y1-(h+pad)*a.height,w*a.width,h*a.height], projection="hammer")
answered Mar 27 at 21:40
Diziet AsahiDiziet Asahi
11.9k3 gold badges21 silver badges32 bronze badges
11.9k3 gold badges21 silver badges32 bronze badges
thank you so much! just having an experiment with both answers now
– Tommy Lees
Mar 27 at 22:39
This also works! I don't quite know how which to select but both are great answers!
– Tommy Lees
Mar 30 at 22:00
add a comment |
thank you so much! just having an experiment with both answers now
– Tommy Lees
Mar 27 at 22:39
This also works! I don't quite know how which to select but both are great answers!
– Tommy Lees
Mar 30 at 22:00
thank you so much! just having an experiment with both answers now
– Tommy Lees
Mar 27 at 22:39
thank you so much! just having an experiment with both answers now
– Tommy Lees
Mar 27 at 22:39
This also works! I don't quite know how which to select but both are great answers!
– Tommy Lees
Mar 30 at 22:00
This also works! I don't quite know how which to select but both are great answers!
– Tommy Lees
Mar 30 at 22:00
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55385515%2fembed-small-map-cartopy-on-matplotlib-figure%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown