# Inserting image in corner of plot without affecting aspect ratio

**URL:** <https://discourse.julialang.org/t/inserting-image-in-corner-of-plot-without-affecting-aspect-ratio/113631>\
**Category:** General Usage\
**Tags:** images, plotting\
**Created:** [April 29, 2024, 9:42pm UTC](https://discourse.julialang.org/t/inserting-image-in-corner-of-plot-without-affecting-aspect-ratio/113631 "2024-04-29T21:42:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hshackle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hshackle/32/47114_2.png) [@hshackle](https://discourse.julialang.org/u/hshackle)\
**Post date:** [April 29, 2024, 9:42pm UTC](https://discourse.julialang.org/t/inserting-image-in-corner-of-plot-without-affecting-aspect-ratio/113631/1 "2024-04-29T21:42:55Z")

</div>

I have a `png` image that I would like to include in the corner of a plot. It seems that there is functionality for putting images in plots, but I could not find an easy way of doing what I wanted. Below is an example:

```julia
using Plots
using Images

img = load("image.png")
x = 0:0.01:2pi
y = sin.(x)
plot(x, y)
plot!([0, 1], [0, 1], img)

```

This does put the image in the plot in the region x=(0, 1), y=(0, 1), but it modifies the aspect ratio of the original image such that the picture is undistorted. With some careful geometry I could deduce exactly the region I would need to include in order to not distort the aspect ratio, but I was hoping that there is a simpler way to just drop in the image centered at a given (x,y) point without doing anything to the aspect ratio. Apparently the command `plot!(x, y, img)` does not work. Is there a way to do this?

---

<div class="post-metadata">

**Author:** ![aryavorskiy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aryavorskiy/32/43466_2.png) [@aryavorskiy](https://discourse.julialang.org/u/aryavorskiy)\
**Post date:** [April 29, 2024, 10:45pm UTC](https://discourse.julialang.org/t/inserting-image-in-corner-of-plot-without-affecting-aspect-ratio/113631/2 "2024-04-29T22:45:22Z")

</div>

Hi!

There is no good way to control the image position, apparently. What you might want to do in your case is creating an [inset plot](https://docs.juliaplots.org/latest/layouts/#Advanced-Layouts):

```julia
plot(x, y)
# The bbox controls the inset position: x, y, w, h (in relative units)
plot!(img, inset=bbox(0,0,0.5,0.5), subplot=2, axes=:none, ticks=[], aspect=1)

```

Here is what keyword arguments do:

- `inset=bbox(0,0,0.5,0.5), subplot=2`: create the inset and make sure you plot into it and not the main plot
- `axes=:none, ticks=[]`: hide axes and ticks for the inset
- `aspect=1`: keep aspect ratio

You will end up with something like this:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/a/dac0316455d7bf7781ebdef6d57fd76f2246974e.jpeg)

---

<div class="post-metadata">

**Author:** ![hshackle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hshackle/32/47114_2.png) [@hshackle](https://discourse.julialang.org/u/hshackle)\
**Post date:** [April 30, 2024, 1:47am UTC](https://discourse.julialang.org/t/inserting-image-in-corner-of-plot-without-affecting-aspect-ratio/113631/3 "2024-04-30T01:47:00Z")

</div>

Thanks! This does seem to work, although I also needed to include the `showaxis=false` option in order to completely hide the axis.
