1

I have an issue that has been plaguing me since I started working on notebook python. I have a simple snippet to display an image of type float64 with a size of [714,180]

evidence = hough_forests(edges)
fig = plt.figure(figsize=(20, 20))
plt.imshow(evidence, cmap="gray")

No matter what value I put in figsize, the image appears squeezed because it has a lot more rows than columns. I have tried

import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (20,20)

posted How do you change the size of figures drawn with matplotlib? but it does not work as well. I noticed that the figsize command only works when I am using subplots for multiple images.

It also does not work if I set aspect='equal'

enter image description here

Kong
  • 2,202
  • 8
  • 28
  • 56
  • ```plt.imshow(evidence, cmap="gray", aspect='equal')```? – sascha Mar 30 '18 at 22:19
  • @sascha thanks, i have tried your suggestion but it seems it is being ignored. is it an issue with my installation ? – Kong Mar 30 '18 at 22:23
  • @sascha do you mean dtype ? if so, then i have added in my post that the image is of type float64. But I am not sure how the type of the image would control the output of imshow – Kong Mar 30 '18 at 22:26
  • So what exactly do you want to see? The original shape (which i assumed above and i'm now unsure of; equal should do) or a square (given the figsize, auto should do that i suppose)? I don't get that from your statements. Apart from that: did you check the values inside the array? Do some minmax or scipy.stats.describe on that. To be honest: it's hard(er) to help with code we can't run. – sascha Mar 30 '18 at 22:27
  • @sascha sorry if it was not clear enough. What I wanted is for the height and width of the figure to resemble figsize i.e. if figsize=(20,20) then the output should be scaled accordingly such that it is a square, if figsize(10,20) then it should look like a rectangle. – Kong Mar 30 '18 at 22:35
  • 3
    In general the figure size has nothing to do with the aspect ratio of the axes in it. Here it seems you are interested in the aspect, not the size. You may set the aspect to `"auto"`, `"equal"` or just some number that you like. – ImportanceOfBeingErnest Mar 30 '18 at 22:35

1 Answers1

0

Okay so I learnt that I have to manually

(1) set aspect to get the aspect ratio that I want

(2) set figsize to get the figure size that I want

fig = plt.figure(figsize=(10,10))
plt.imshow(hough_lines(edges), cmap="gray", aspect=0.2)

I was hoping that I would need to set only the figure size and have the aspect ratio automatically determine from that. Thanks to the comments above for the answers :)

Kong
  • 2,202
  • 8
  • 28
  • 56