Help with PyPlot -- How to change the aspect ratio of a plot

1,794 views
Skip to first unread message

Daniel Carrera

unread,
Apr 12, 2014, 6:08:27 PM4/12/14
to julia...@googlegroups.com
Hello,

I use PyPlot for my work. I normally manage to figure out how to do things by reading the Matplotlib documentation, but this time I am really stuck. I want to make a plot that has an unusual aspect ratio. I need it to be four times taller than it is wide (the plot is a 2D image). The candidate solution I found is the "set_aspect()" function from Matplotlib:



So, based on this, I looked for a function called "set_aspect()" or "aspect()", but there is none. I looked for an "aspect" parameter for the "axis()" command, but there does not appear to be one (hard to say for sure because "axis()" doesn't give an error if you pass a parameter it doesn't know about.

Can anyone help me?

Cheers,
Daniel.

Adrian Cuthbertson

unread,
Apr 13, 2014, 1:16:36 AM4/13/14
to julia...@googlegroups.com
Hi Daniel, this worked for me in IJulia...

using PyPlot
using PyCall

img = imread("ada.png");
fig = plt.figure()
ax = plt.Axes(fig,[0,0,1,1])
fig[:add_axes](ax)
ax[:set_axis_off]()
ax[:imshow](img,aspect="auto")
ax[:set_aspect](0.5)
plt.show()

Adrian.

Daniel Carrera

unread,
Apr 14, 2014, 4:58:39 AM4/14/14
to julia...@googlegroups.com
Thanks! That was very helpful.

Cheers,
Daniel.
--
When an engineer says that something can't be done, it's a code phrase that means it's not fun to do.
Reply all
Reply to author
Forward
0 new messages