Search code examples
pythonmatplotlibplotscaleimshow

Plotting log plot over image


I have data that I need to plot on a log scale, and I would like to plot an image in the backgroud. Keep in mind, that the image should fill the extent of the log plot. The problema is, when setting the scales to log, the image is distorted. The image is plotted in log scale as well (I think). I think I would have to decouple both axis, or something like that. I've tried a few things, but either the image doesn't fill the extent of the log plot or the image is distorted.

This is my original code:

plt.scatter(df['razao atrito'],df['resistencia'],zorder=2)
plt.xscale("log",nonposx="mask")
plt.xlim(0.1,10)
plt.yscale("log",nonposy="mask")
plt.ylim(1,1000)
img=plt.imread("Capture.jpg")
plt.imshow(img,aspect='auto',zorder=1,extent=[0.1,10,1,1000])

Solution

  • you should add a transform=ax.transAxes in imshow and a 0-1 extent so that it is shown in the axes coordinates.