# grid on log-plots

Hi,

can anybody tell me how to get gridlines in a logarithmic plot?

i tried eg.:
loglog([1,10,100], [1,10,100])
grid(True)

but neither the grid is drawn, nor an error occur. When i make a linear plot, grid(True) works fine and draws the grid.

(win32, python 2.6, matplotlib 0.99)

Thanks

jihi wrote:

... can anybody tell me how to get gridlines in a logarithmic plot? ...

from matplotlib.pyplot import *

plot([1,10,100],[1,10,100])
grid()

yscale('log')
xscale('log')

works here.

best,
sebastian.

thanks Sebastian,

you are right, your code works here too. But i don't get it work in my multi y-axes plot from the matplotlib examples (http://matplotlib.sourceforge.net/examples/axes_grid/demo_parasite_axes.html). Even with linear plots, i get no gridlines.

Any idea, whats wrong here?

minimal code example:

···

#######################
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.parasite_axes import HostAxes, ParasiteAxes

fig = plt.figure(1)
fig.clf()
#plt.grid(True)
host = HostAxes(fig, [0.15, 0.1, 0.65, 0.8])

host.plot([0, 10, 100], [0, 10, 100], label='host')

host.grid(True) #?
host.yaxis.grid(True) #?

host.yaxis.set_scale('log') #?

plt.draw()
plt.show()
#######################

Greets,
Andreas

Sebastian Busch schrieb:

from matplotlib.pyplot import *

plot([1,10,100],[1,10,100])
grid()

yscale('log')
xscale('log')

works here.

best,
sebastian.

This is a bug in the axes_grid toolkit. As a matter of fact, gridlines
in rectlinear coordinate are not implemented yet.
Unfortunately, I don't see any easy workarounds.

You may use mpl's original axis artists, but some of the functionality
of axes_grid toolkit may be lost.

host.toggle_axisline(False)
host.yaxis.set_ticks_position("left")
host.yaxis.grid()
host.set_yscale("log")

With new spine support in mpl, I think a similar plot can be drawn
without using axes_grid toolkit.

Regards,

-JJ

···

On Mon, Sep 7, 2009 at 4:37 PM, Andreas Fromm<anfromm@...380...> wrote:

thanks Sebastian,

you are right, your code works here too. But i don't get it work in my
multi y-axes plot from the matplotlib examples
(http://matplotlib.sourceforge.net/examples/axes_grid/demo_parasite_axes.html).
Even with linear plots, i get no gridlines.

Any idea, whats wrong here?

minimal code example:
#######################
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.parasite_axes import HostAxes, ParasiteAxes

fig = plt.figure(1)
fig.clf()
#plt.grid(True)
host = HostAxes(fig, [0.15, 0.1, 0.65, 0.8])

host.plot([0, 10, 100], [0, 10, 100], label='host')

host.grid(True) #?
host.yaxis.grid(True) #?

host.yaxis.set_scale('log') #?

plt.draw()
plt.show()
#######################

Greets,
Andreas

Sebastian Busch schrieb:

from matplotlib.pyplot import *

plot([1,10,100],[1,10,100])
grid()

yscale('log')
xscale('log')

works here.

best,
sebastian.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Hi,

I have the same behaviour with LocatableAxes. HostAxes, ParasiteAxes and LocatableAxes depend on 'mpl_toolkits.axes_grid.axislines.Axes'. It must be the matter origin.
This another example should draw a grid but does not:

import wx
from wx import Frame
from matplotlib.backends.backend_wxagg import FigureFrameWxAgg, FigureCanvasWxAgg
from matplotlib.figure import Figure
from mpl_toolkits.axes_grid.axes_divider import LocatableAxes

fig = Figure((1, 1), 50)
axes = LocatableAxes(fig, [0, 0, 1, 1])
# axes.toggle_axisline(False)
axes.grid(True)

app = wx.PySimpleApp()
my_viewer = FigureFrameWxAgg(-1, fig)
my_viewer.Show()
app.MainLoop()

If you uncomment axes.toggle_axisline(False), it works cause it uses normal 'matplolib.axes.Axes' behaviour. It is not a matter for common use but if you need 'AxesZero', this trick does not work.

Yann

···

On 09/07/2009 10:37 PM, Andreas Fromm wrote:

thanks Sebastian,

you are right, your code works here too. But i don't get it work in my
multi y-axes plot from the matplotlib examples
(http://matplotlib.sourceforge.net/examples/axes_grid/demo_parasite_axes.html).
Even with linear plots, i get no gridlines.

Any idea, whats wrong here?

minimal code example:
#######################
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.parasite_axes import HostAxes, ParasiteAxes

fig = plt.figure(1)
fig.clf()
#plt.grid(True)
host = HostAxes(fig, [0.15, 0.1, 0.65, 0.8])

host.plot([0, 10, 100], [0, 10, 100], label='host')

host.grid(True) #?
host.yaxis.grid(True) #?

host.yaxis.set_scale('log') #?

plt.draw()
plt.show()
#######################

Greets,
Andreas

Sebastian Busch schrieb:

from matplotlib.pyplot import *

plot([1,10,100],[1,10,100])
grid()

yscale('log')
xscale('log')

works here.

best,
sebastian.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Hi,

I have the same behaviour with LocatableAxes. HostAxes, ParasiteAxes and
LocatableAxes depend on 'mpl_toolkits.axes_grid.axislines.Axes'. It must
be the matter origin.

Yes, and this was because I forgot to implement some necessary methods.
This is now fixed in the svn trunk. So if you can,please give it a try.

This another example should draw a grid but does not:

import wx
from wx import Frame
from matplotlib.backends.backend_wxagg import FigureFrameWxAgg,
FigureCanvasWxAgg
from matplotlib.figure import Figure
from mpl_toolkits.axes_grid.axes_divider import LocatableAxes

fig = Figure((1, 1), 50)
axes = LocatableAxes(fig, [0, 0, 1, 1])
# axes.toggle_axisline(False)
axes.grid(True)

app = wx.PySimpleApp()
my_viewer = FigureFrameWxAgg(-1, fig)
my_viewer.Show()
app.MainLoop()

If you uncomment axes.toggle_axisline(False), it works cause it uses
normal 'matplolib.axes.Axes' behaviour. It is not a matter for common
use but if you need 'AxesZero', this trick does not work.

What the toggle_axisline does is simply to make the xaxis and yaxis
(which are responsible for drawing ticks, ticklabels, etc in the
mainline mpl) visible again, and make axis["bottom"] and etc
invisible.
One workaround is to make xaxis and yaxis visible but pnly to draw the
gridlines. Something like below.

ax.toggle_axisline(True)
ax.grid(True)
ax.gridlines.set_visible(False) # this is just to make the code not to
draw gridlines twice in future release of mpl.
ax.xaxis.set_visible(True)
ax.yaxis.set_visible(True)
for t in ax.xaxis.majorTicks + ax.yaxis.majorTicks:
t.gridOn = True
t.tick1On = False
t.tick2On = False
t.label1On = False
t.label2On = False

Let me know if this does not work, or there is a case that this cannot be used.
Regards,

-JJ

···

On Tue, Sep 8, 2009 at 11:51 AM, Yann Goudard<matplotlib-users@...2772...> wrote:

Yann

On 09/07/2009 10:37 PM, Andreas Fromm wrote:

thanks Sebastian,

you are right, your code works here too. But i don't get it work in my
multi y-axes plot from the matplotlib examples
(http://matplotlib.sourceforge.net/examples/axes_grid/demo_parasite_axes.html).
Even with linear plots, i get no gridlines.

Any idea, whats wrong here?

minimal code example:
#######################
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.parasite_axes import HostAxes, ParasiteAxes

fig = plt.figure(1)
fig.clf()
#plt.grid(True)
host = HostAxes(fig, [0.15, 0.1, 0.65, 0.8])

host.plot([0, 10, 100], [0, 10, 100], label='host')

host.grid(True) #?
host.yaxis.grid(True) #?

host.yaxis.set_scale('log') #?

plt.draw()
plt.show()
#######################

Greets,
Andreas

Sebastian Busch schrieb:

from matplotlib.pyplot import *

plot([1,10,100],[1,10,100])
grid()

yscale('log')
xscale('log')

works here.

best,
sebastian.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

I can not try your revision but I will do it as soon as it is released.
Nervertheless I try your snippet with an AxesZero. I get the gridlines and the axis but the first was over the second. It is not what I expected.
As far as I am concerned, I can wait until matplotlib next release.

Thanks,

Yann

···

On 09/08/2009 08:13 PM, Jae-Joon Lee wrote:

On Tue, Sep 8, 2009 at 11:51 AM, Yann > Goudard<matplotlib-users@...2772...> wrote:

Hi,

I have the same behaviour with LocatableAxes. HostAxes, ParasiteAxes and
LocatableAxes depend on 'mpl_toolkits.axes_grid.axislines.Axes'. It must
be the matter origin.

Yes, and this was because I forgot to implement some necessary methods.
This is now fixed in the svn trunk. So if you can,please give it a try.

This another example should draw a grid but does not:

import wx
from wx import Frame
from matplotlib.backends.backend_wxagg import FigureFrameWxAgg,
FigureCanvasWxAgg
from matplotlib.figure import Figure
from mpl_toolkits.axes_grid.axes_divider import LocatableAxes

fig = Figure((1, 1), 50)
axes = LocatableAxes(fig, [0, 0, 1, 1])
# axes.toggle_axisline(False)
axes.grid(True)

app = wx.PySimpleApp()
my_viewer = FigureFrameWxAgg(-1, fig)
my_viewer.Show()
app.MainLoop()

If you uncomment axes.toggle_axisline(False), it works cause it uses
normal 'matplolib.axes.Axes' behaviour. It is not a matter for common
use but if you need 'AxesZero', this trick does not work.

What the toggle_axisline does is simply to make the xaxis and yaxis
(which are responsible for drawing ticks, ticklabels, etc in the
mainline mpl) visible again, and make axis["bottom"] and etc
invisible.
One workaround is to make xaxis and yaxis visible but pnly to draw the
gridlines. Something like below.

ax.toggle_axisline(True)
ax.grid(True)
ax.gridlines.set_visible(False) # this is just to make the code not to
draw gridlines twice in future release of mpl.
ax.xaxis.set_visible(True)
ax.yaxis.set_visible(True)
for t in ax.xaxis.majorTicks + ax.yaxis.majorTicks:
t.gridOn = True
t.tick1On = False
t.tick2On = False
t.label1On = False
t.label2On = False

Let me know if this does not work, or there is a case that this cannot be used.
Regards,

-JJ

Yann

On 09/07/2009 10:37 PM, Andreas Fromm wrote:

thanks Sebastian,

you are right, your code works here too. But i don't get it work in my
multi y-axes plot from the matplotlib examples
(http://matplotlib.sourceforge.net/examples/axes_grid/demo_parasite_axes.html).
Even with linear plots, i get no gridlines.

Any idea, whats wrong here?

minimal code example:
#######################
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.parasite_axes import HostAxes, ParasiteAxes

fig = plt.figure(1)
fig.clf()
#plt.grid(True)
host = HostAxes(fig, [0.15, 0.1, 0.65, 0.8])

host.plot([0, 10, 100], [0, 10, 100], label='host')

host.grid(True) #?
host.yaxis.grid(True) #?

host.yaxis.set_scale('log') #?

plt.draw()
plt.show()
#######################

Greets,
Andreas

Sebastian Busch schrieb:

from matplotlib.pyplot import *

plot([1,10,100],[1,10,100])
grid()

yscale('log')
xscale('log')

works here.

best,
sebastian.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

I can not try your revision but I will do it as soon as it is released.
Nervertheless I try your snippet with an AxesZero. I get the gridlines
and the axis but the first was over the second. It is not what I expected.

You can rearrange the order of artists by setting the zorder.

As far as I am concerned, I can wait until matplotlib next release.

Just to clarify, the patch will be included in the 1.0 release, not
the maintenance release of 0.99 version.

Regards,

-JJ

···

On Wed, Sep 9, 2009 at 4:30 AM, Yann<yann@...2772...> wrote:

Thanks,

Yann

On 09/08/2009 08:13 PM, Jae-Joon Lee wrote:

On Tue, Sep 8, 2009 at 11:51 AM, Yann >> Goudard<matplotlib-users@...2772...> wrote:

Hi,

I have the same behaviour with LocatableAxes. HostAxes, ParasiteAxes and
LocatableAxes depend on 'mpl_toolkits.axes_grid.axislines.Axes'. It must
be the matter origin.

Yes, and this was because I forgot to implement some necessary methods.
This is now fixed in the svn trunk. So if you can,please give it a try.

This another example should draw a grid but does not:

import wx
from wx import Frame
from matplotlib.backends.backend_wxagg import FigureFrameWxAgg,
FigureCanvasWxAgg
from matplotlib.figure import Figure
from mpl_toolkits.axes_grid.axes_divider import LocatableAxes

fig = Figure((1, 1), 50)
axes = LocatableAxes(fig, [0, 0, 1, 1])
# axes.toggle_axisline(False)
axes.grid(True)

app = wx.PySimpleApp()
my_viewer = FigureFrameWxAgg(-1, fig)
my_viewer.Show()
app.MainLoop()

If you uncomment axes.toggle_axisline(False), it works cause it uses
normal 'matplolib.axes.Axes' behaviour. It is not a matter for common
use but if you need 'AxesZero', this trick does not work.

What the toggle_axisline does is simply to make the xaxis and yaxis
(which are responsible for drawing ticks, ticklabels, etc in the
mainline mpl) visible again, and make axis["bottom"] and etc
invisible.
One workaround is to make xaxis and yaxis visible but pnly to draw the
gridlines. Something like below.

ax.toggle_axisline(True)
ax.grid(True)
ax.gridlines.set_visible(False) # this is just to make the code not to
draw gridlines twice in future release of mpl.
ax.xaxis.set_visible(True)
ax.yaxis.set_visible(True)
for t in ax.xaxis.majorTicks + ax.yaxis.majorTicks:
t.gridOn = True
t.tick1On = False
t.tick2On = False
t.label1On = False
t.label2On = False

Let me know if this does not work, or there is a case that this cannot be used.
Regards,

-JJ

Yann

On 09/07/2009 10:37 PM, Andreas Fromm wrote:

thanks Sebastian,

you are right, your code works here too. But i don't get it work in my
multi y-axes plot from the matplotlib examples
(http://matplotlib.sourceforge.net/examples/axes_grid/demo_parasite_axes.html).
Even with linear plots, i get no gridlines.

Any idea, whats wrong here?

minimal code example:
#######################
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.parasite_axes import HostAxes, ParasiteAxes

fig = plt.figure(1)
fig.clf()
#plt.grid(True)
host = HostAxes(fig, [0.15, 0.1, 0.65, 0.8])

host.plot([0, 10, 100], [0, 10, 100], label='host')

host.grid(True) #?
host.yaxis.grid(True) #?

host.yaxis.set_scale('log') #?

plt.draw()
plt.show()
#######################

Greets,
Andreas

Sebastian Busch schrieb:

from matplotlib.pyplot import *

plot([1,10,100],[1,10,100])
grid()

yscale('log')
xscale('log')

works here.

best,
sebastian.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Hi,

is it enough to overwrite the axesgrid.py file in my matplotlib 0.99 installation with the file from svn? I tried that, but i see no effects. Are there anywhere precompiled matplotlib releases for 1.0_win32_pre?

Andreas

Jae-Joon Lee schrieb:

···

On Tue, Sep 8, 2009 at 11:51 AM, Yann > Goudard<matplotlib-users@...2772...> wrote:

Hi,

I have the same behaviour with LocatableAxes. HostAxes, ParasiteAxes and
LocatableAxes depend on 'mpl_toolkits.axes_grid.axislines.Axes'. It must
be the matter origin.

Yes, and this was because I forgot to implement some necessary methods.
This is now fixed in the svn trunk. So if you can,please give it a try.

This another example should draw a grid but does not:

import wx
from wx import Frame
from matplotlib.backends.backend_wxagg import FigureFrameWxAgg,
FigureCanvasWxAgg
from matplotlib.figure import Figure
from mpl_toolkits.axes_grid.axes_divider import LocatableAxes

fig = Figure((1, 1), 50)
axes = LocatableAxes(fig, [0, 0, 1, 1])
# axes.toggle_axisline(False)
axes.grid(True)

app = wx.PySimpleApp()
my_viewer = FigureFrameWxAgg(-1, fig)
my_viewer.Show()
app.MainLoop()

If you uncomment axes.toggle_axisline(False), it works cause it uses
normal 'matplolib.axes.Axes' behaviour. It is not a matter for common
use but if you need 'AxesZero', this trick does not work.

What the toggle_axisline does is simply to make the xaxis and yaxis
(which are responsible for drawing ticks, ticklabels, etc in the
mainline mpl) visible again, and make axis["bottom"] and etc
invisible.
One workaround is to make xaxis and yaxis visible but pnly to draw the
gridlines. Something like below.

ax.toggle_axisline(True)
ax.grid(True)
ax.gridlines.set_visible(False) # this is just to make the code not to
draw gridlines twice in future release of mpl.
ax.xaxis.set_visible(True)
ax.yaxis.set_visible(True)
for t in ax.xaxis.majorTicks + ax.yaxis.majorTicks:
t.gridOn = True
t.tick1On = False
t.tick2On = False
t.label1On = False
t.label2On = False

Let me know if this does not work, or there is a case that this cannot be used.
Regards,

-JJ

Yann

On 09/07/2009 10:37 PM, Andreas Fromm wrote:

thanks Sebastian,

you are right, your code works here too. But i don't get it work in my
multi y-axes plot from the matplotlib examples
(http://matplotlib.sourceforge.net/examples/axes_grid/demo_parasite_axes.html).
Even with linear plots, i get no gridlines.

Any idea, whats wrong here?

minimal code example:
#######################
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.parasite_axes import HostAxes, ParasiteAxes

fig = plt.figure(1)
fig.clf()
#plt.grid(True)
host = HostAxes(fig, [0.15, 0.1, 0.65, 0.8])

host.plot([0, 10, 100], [0, 10, 100], label='host')

host.grid(True) #?
host.yaxis.grid(True) #?

host.yaxis.set_scale('log') #?

plt.draw()
plt.show()
#######################

Greets,
Andreas

Sebastian Busch schrieb:

from matplotlib.pyplot import *

plot([1,10,100],[1,10,100])
grid()

yscale('log')
xscale('log')

works here.

best,
sebastian.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options