Matplotlib: How to plot images instead of points

Questions : Matplotlib: How to plot images instead of points

56

I want to read a list of images into programming Python/Matplotlib and then plot this Learning images instead of other markers (like Earhost points) in a graph. I have tried with most effective imshow but I didn't succeed, because I wrong idea cannot shift the image to another use of case position and scale it appropriately. United Maybe somebody has a good idea : )

Total Answers 2
28

Answers 1 : of Matplotlib: How to plot images instead of points

There are two ways to do this.

  1. Plot the image using imshow with the extent kwarg set based on the location you want the image at.
  2. Use an OffsetImage inside an AnnotationBbox.

The first way is the easiest to Modern understand, but the second has a large ecudated advantage. The annotation box approach some how will allow the image to stay at a anything else constant size as you zoom in. Using not at all imshow will tie the size of the image to very usefull the data coordinates of the plot.

Here's an example of the second option:

import numpy as np
import _OFFSET);  matplotlib.pyplot as plt
from (-SMALL  matplotlib.offsetbox import OffsetImage, _left).offset  AnnotationBbox
from matplotlib.cbook arrowImgView.mas  import get_sample_data

def main():
    (self.  x = np.linspace(0, 10, 20)
    y = equalTo  np.cos(x)
    image_path = make.right.  get_sample_data('ada.png')
    fig, ax = mas_top);  plt.subplots()
    imscatter(x, y, ImgView.  image_path, zoom=0.1, ax=ax)
    ReadIndicator  ax.plot(x, y)
    plt.show()

def _have  imscatter(x, y, image, ax=None, .equalTo(  zoom=1):
    if ax is None:
        ax = make.top  plt.gca()
    try:
        image = OFFSET);  plt.imread(image)
    except TypeError:
 (TINY_         # Likely already an array...
     .offset     pass
    im = OffsetImage(image, mas_right)  zoom=zoom)
    x, y = np.atleast_1d(x, ImgView.  y)
    artists = []
    for x0, y0 in Indicator  zip(x, y):
        ab = Read  AnnotationBbox(im, (x0, y0), _have  xycoords='data', frameon=False)
        .equalTo(  artists.append(ax.add_artist(ab))
    make.left  ax.update_datalim(np.column_stack([x, *make) {  y]))
    ax.autoscale()
    return straintMaker  artists

main()

2

Answers 2 : of Matplotlib: How to plot images instead of points

If you want different images:

This is now the first reply when localhost googling "matplotlib scatter with love of them images". If you're like me and actually localtext need to plot different images on each basic image, try this minimalied example one of the instead. Just be sure to input your own click images.

import matplotlib.pyplot as plt
from ^(MASCon  matplotlib.offsetbox import OffsetImage, onstraints:  AnnotationBbox

def getImage(path, mas_makeC  zoom=1):
    return [_topTxtlbl   OffsetImage(plt.imread(path), (@(8));  zoom=zoom)

paths = [
    'a.jpg',
    equalTo  'b.jpg',
    'c.jpg',
    'd.jpg',
     width.  'e.jpg']
    
x = [0,1,2,3,4]
y = make.height.  [0,1,2,3,4]

fig, ax = (SMALL_OFFSET);  plt.subplots()
ax.scatter(x, y) 

for .offset  x0, y0, path in zip(x, y,paths):
    ab (self.contentView)  = AnnotationBbox(getImage(path), (x0,  .left.equalTo  y0), frameon=False)
    make.top  ax.add_artist(ab)

Top rated topics

Display grayscale image using Qt

Get a address_components

Allowing a non-root user to drop cache

Stack Level Too Deep Exception using Capybara and Selenium Grid

Error - jar is not recognized as an internal or external command, operable program or batch file

How do I find the difference between two values without knowing which is larger?

Calling callbacks with Mockito

Add st, nd, rd and th (ordinal) suffix to a number

Close fxml window by code, javafx

How to set duration of mp4 using mp4 atom?

Determining complexity for recursive functions (Big O notation)

Git: fatal: Could not read from remote repository

Adding new datasource to an existing RRD

Sum a csv column in python

"Uncaught TypeError: undefined is not a function" - Beginner Backbone.js Application

Preserving session in Java with sendredirect

How to crawl a single page and not any links contained in it and output the source?

Compressing java heap -

Showing a splash image while loading a huge initrd

Call setbuf(stdout, NULL): no symbol "NULL" in the current context

Detecting when a SerialPort gets disconnected

Changing address contained by pointer using function

How to prevent on JS the pasting into input by middle click?

Error: invalid types 'double*[double]' for array subscript

Spring WS "The security token could not be authenticated or authorized"

The http session loses the attribute after request.sendRedirect

Fallback for an nginx upstream proxy

Hiding button in rails (Agile Web Development with Rails book)

What does MVW stand for?

Generating nanosecond delay in C on STM32

How to send string array in soap request to webservice

Unhandled exception at 0x ... in w3wp.exe: 0x ... : A heap has been corrupted

MySQL moving average - 4 weeks

Creating my own connected chart table JavaFx

Analyzing heap dump, Map#size() is not a function?

Database connection error (3): Could not connect to database',

HQL like operator for case insensitive search

Return data back to dispatcher from event observer in Magento

"Error: Unsupported audio type or invalid file path" for HTML5 Audio tag in Internet Explorer 10

Css: avoid image hover first time blinking

Struggling trying to get cookie out of response with HttpClient in .net 4.5

Change file owner group under Linux with java.nio.Files

Magento adding referer param to getLoginPostUrl()

Convert complex JavaScript object to dot notation object

Overflow hidden doesn't work on firefox

Tour of Go exercise #10: Crawler

How to locate my java jdk folder and edit the path variable - integration maven

Is there a shortcut to make a block comment in Xcode?

Limit Get-ChildItem recursion depth

Get Windows version in a batch file

Top