Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8224973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:15:21+00:00 2026-06-07T15:15:21+00:00

I am plotting data from an aircraft on a map and I would like

  • 0

I am plotting data from an aircraft on a map and I would like to insert this 75px by 29px PNG image of an airplane at the coordinates of the latest data point on the plot.

airplane

As far as I know and have read, pyplot.imshow() is the best way to accomplish this. However, I am getting hung up on step 1, getting the image to even display. Using a normal plot instead of Basemap, it is easy enough to get the image to appear using imshow, but when using Basemap, I can’t get it to show up at all. See the example code.

If I can get the image to display on the map, I am assuming that I can, by trial and error, set its position and some proper dimensions for it using the extent attribute of imshow(), with the plot coordinates converted from the map coordinates x,y = m(lons,lats).

Here is the example code (to try it you may want to download the airplane image above).

from matplotlib import pyplot as plt
from mpl_toolkits.basemap import Basemap
import Image
from numpy import arange

lats = arange(26,29,0.5)
lons = arange(-90,-87,0.5)

m = Basemap(projection='cyl',llcrnrlon=min(lons)-2,llcrnrlat=min(lats)-2,
            urcrnrlon=max(lons)+2,urcrnrlat=max(lats)+2,resolution='i')

x,y = m(lons,lats)
u,v, = arange(0,51,10),arange(0,51,10)
barbs = m.barbs(x,y,u,v)
m.drawcoastlines(); m.drawcountries(); m.drawstates()

img = Image.open('c130j_75px.png')
im = plt.imshow(img, extent=(x[-1],x[-1]+50000,y[-1],y[-1]+50000))
plt.show()

Here’s the resulting image, which doesn’t contain a trace of the airplane. I have tried several different sizes using extent, thinking I may have just made it too small, but with no success. I also tried setting zorder=10, but also with no luck. Any help would be appreciated.

result

Update: I can now get the image to at least appear by using m.imshow instead of plt.imshow, since the former passes in the map’s axes instance, but the extent argument seems to have no effect on the dimensions of the image, as it always fills up the entire plot no matter how small I make extent dimensions, even if I set them to zero. How can I scale the airplane image appropriately and position it near the last data point?

im = m.imshow(img, extent=(x[-1],x[-1]+5,y[-1],y[-1]+2))

result2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:15:22+00:00Added an answer on June 7, 2026 at 3:15 pm

    Actually, for this you want to use a somewhat undocumented feature of matplotlib: the matplotlib.offsetbox module. There’s an example here: http://matplotlib.sourceforge.net/trunk-docs/examples/pylab_examples/demo_annotation_box.html

    In your case, you’d do something like this:

    import matplotlib.pyplot as plt
    import numpy as np
    import Image
    
    from mpl_toolkits.basemap import Basemap
    from matplotlib.offsetbox import OffsetImage, AnnotationBbox
    
    # Set up the basemap and plot the markers.
    lats = np.arange(26, 29, 0.5)
    lons = np.arange(-90, -87, 0.5)
    
    m = Basemap(projection='cyl',
                llcrnrlon=min(lons) - 2, llcrnrlat=min(lats) - 2,
                urcrnrlon=max(lons) + 2, urcrnrlat=max(lats) + 2,
                resolution='i')
    
    x,y = m(lons,lats)
    u,v, = np.arange(0,51,10), np.arange(0,51,10)
    barbs = m.barbs(x,y,u,v)
    
    m.drawcoastlines()
    m.drawcountries()
    m.drawstates()
    
    # Add the plane marker at the last point.
    plane = np.array(Image.open('plane.jpg'))
    im = OffsetImage(plane, zoom=1)
    ab = AnnotationBbox(im, (x[-1],y[-1]), xycoords='data', frameon=False)
    
    # Get the axes object from the basemap and add the AnnotationBbox artist
    m._check_ax().add_artist(ab)
    
    plt.show()
    

    enter image description here

    The advantage to this is that the plane is in axes coordinates and will stay the same size relative to the size of the figure when zooming in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am plotting boxplots from this data: MY_LABEL MY_REAL MY_CATEGORY 1 [POS] .56 POS
I'm plotting some data curves with gnuplot, and they look like this: However, the
I am plotting a raster image from the data stored in a file by
I am plotting a scatter plot on a Basemap. However, the data with this
I'm plotting data which extent, in x, from -1000 to 1000. But I'm only
I can capture data from serial device via pyserial, at this time I can
I'm plotting data in Python using matplotlib. I am updating the data of the
I'm facing a problem with plotting data using the CorePlot framework. I have integrated
I spend most of my time plotting data, but unfortunately I haven't found a
I have a scaling problem with XYChart plotting: my data serie ranges in float

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.