2

How can I manage to make a imshow() figure whitout any padding or axes?

I seem to have an usual problem that has been answered here before, but none of the solutions work for me. I have a figure generated by PyPlot under Julia, which is apparently a frontend for matplotlib.pyplot, and "should" behave accordingly. The problem is that I can manage in Jupyter to have a figure without white padding or bounding box. But when I save, it insists on putting the bounding box around.

I have tried the solutions in this thread and also in this other thread. None worked. Here is my code:

blabla=randn(40,500)
tuabuela=PyPlot.figure(frameon=false)
gca().set_axis_off()
subplots_adjust(top = 1, bottom = 0, right = 1, left = 0, 
            hspace = 0, wspace = 0)

tu=imshow(blabla, interpolation="gaussian")
margins(0,0)
savefig("outname.png", bbox_inches="tight", pad_inches=0.01, frameon=false, dpi=90)

The code gives a good image on the Jupyter Notebook, but not at saving. frameon=false seems to only change the frame from white to transparent, not to eliminate it.

My matplotlib is 2.2.2, Python 3.6, and Julia 1.0.3.

The image as it appears on the Notebook (which, i discovered, is the same as the one saved, but the transparent frame was deceptive):

enter image description here

I am perfectly aware that this is a "repeated question", but the hodgepodge of different answers and their non-working status seems to me that the matplotlib library has almost done this more in the direction of changing a feature to a bug....

wpkzz
  • 839
  • 7
  • 23
  • Remove `bbox_inches="tight"`. It's not helpful in getting an image without padding, because it's purpose is to actually produce some padding, especially when `pad_inches` is set to something non-zero. So if `savefig("outname.png", frameon=false, dpi=90)` does not give the desired result, you would want to share an image of the output and state what kind of notebook that is you're working with. – ImportanceOfBeingErnest Jun 18 '19 at 22:12
  • No, that is wrong. If I take that keyword out, it produces a HUGE cuadrangular frame around the image. Also I have tried the `pad_inches⁼0` and other values, the same with `bbox_inches`. No succes. – wpkzz Jun 18 '19 at 23:10
  • Yeah, it seems that that line is also purely ornamental. I have detailed my matplotlib, python and julia versions above, as for the OS is a GNU/Linux machine with a 4.18.5 kernel (gentoo, I know that this can make people roll their eyes, but it is quite well set up). – wpkzz Jun 18 '19 at 23:13
  • I meant what kind of notebook that is? Is the code run all in one cell? Anyways, so what's missing is the figure size. It would need to be adapted to the aspect of the image, in your case `figsize=(500/40, 1)` or so. – ImportanceOfBeingErnest Jun 18 '19 at 23:17
  • The figsize keyword helped somewhat, but I still have pading underneat the figure, even using the exact values of the array sizes. Weird. And the code is run in one cell except for the loading of the data ( in the real life I am using experimental data, not random numbers, but for the example that can be used). By the way, it gives slightly better results with `the subplot_adjust` command. – wpkzz Jun 18 '19 at 23:28
  • Is the figure you show the actual saved image directly uploaded here? Is it produced by `savefig("outname.png", bbox_inches="tight", pad_inches=0, frameon=false, dpi=90)`? Or some other `pad_inches` value? – ImportanceOfBeingErnest Jun 18 '19 at 23:39

0 Answers0