Home > Back-end >  How to control images sizes when plotting scatter plot?
How to control images sizes when plotting scatter plot?

Time:11-26

I want to use scatter plot and instead of ploting dots on plot, I want to plot images.

I'm doing something like:

import matplotlib.pyplot as plt
from matplotlib.offsetbox import OffsetImage, AnnotationBbox

def getImage(path):
    return OffsetImage(plt.imread(path))


paths = get_img_list()

x = mUMAP[0]
y = mUMAP[1]

fig, ax = plt.subplots(figsize=(16, 8), dpi=80)
ax.scatter(x, y) 

for x0, y0, path in zip(x, y,paths):
    ab = AnnotationBbox(getImage(path), (x0, y0), frameon=False, fontsize=2)
    ax.add_artist(ab)

Result: enter image description here

The images are too big.

  • How can I control the size of the image box ?
  • How can I display smaller images ?

CodePudding user response:

You can set the zoom argument from OffsetImage to a value of your liking. Below are two examples: With OffsetImage(plt.imread(path),zoom=0.8):

enter image description here

And with:

OffsetImage(plt.imread(path),zoom=0.2) enter image description here

  • Related