|
From: Eric F. <ef...@ha...> - 2009-05-06 18:54:04
|
Jae-Joon Lee wrote:
> On Wed, May 6, 2009 at 9:49 AM, Sebastian Pająk <spc...@gm...> wrote:
>> Hello
>>
>> How can I set decade on log x axis to be equal length to decade on log
>> y axis (physically)?
>>
>> If I make:
>>
>> ax.set_xscale("log")
>> ax.set_yscale("log")
>> ax.set_aspect(1)
>>
>> I get it all wrong, the units are equal, not decades!!
>>
>> I need the same effect as I get in Gnuplot - the square decades:
>>
>> set logscale yx;
>> set size ratio -1;
>>
>> How can I do it in matplotlib?
>>
>
>
> I'm afraid that this is not directly supported by the matplotlib,
> although I think it should.
> However, you can do it with some monkey patching (or with some other
> similar way).
>
>
> import math
>
> def get_data_ratio(self):
> xmin,xmax = self.get_xbound()
> ymin,ymax = self.get_ybound()
>
> if self.get_xscale() == "log" and self.get_yscale() == "log":
> xsize = max(math.fabs(math.log10(xmax)-math.log10(xmin)), 1e-30)
> ysize = max(math.fabs(math.log10(ymax)-math.log10(ymin)), 1e-30)
> else:
> xsize = max(math.fabs(xmax-xmin), 1e-30)
> ysize = max(math.fabs(ymax-ymin), 1e-30)
>
> return ysize/xsize
>
> from matplotlib.axes import Axes
> Axes.get_data_ratio = get_data_ratio
>
>
> ax = gca()
>
> ax.set_xscale("log")
> ax.set_yscale("log")
> ax.set_aspect(1.)
>
> ax.set_xlim(1, 100)
> ax.set_ylim(1, 1000)
>
>
>
> John and others,
> How do you think this being a default behavior?
Jae-Joon,
Offhand, it looks like a good idea; the current behavior is quite
useless and surprising for a loglog plot.
There are potentially many cases to consider, and probably only those
with both axes being log with the same base can be handled reasonably
with an aspect value other than 'auto'. Maybe cases that cannot be
handled (e.g. semilog*; anything with symmetric log scales except with
symmetric x and y bounds) should raise at least a warning in
apply_aspect, saying that the aspect ratio is being ignored.
Eric
|