Equal decades on loglog axes

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?

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?

Regards,

-JJ

···

On Wed, May 6, 2009 at 9:49 AM, Sebastian Pająk <spconv+m@...287...> wrote:

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Thanks a lot!. I don't understand it but It works now as it should.

2009/5/6 Jae-Joon Lee <lee.j.joon@...287...>:

···

On Wed, May 6, 2009 at 9:49 AM, Sebastian Pająk <spconv+m@...287...> 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?

Regards,

-JJ

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Jae-Joon Lee 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

···

On Wed, May 6, 2009 at 9:49 AM, Sebastian Pająk <spconv+m@...287...> wrote: