Setting color of both major and minor gridlines?

Hello:

I am trying to set different colors for both major and minor gridlines. In essence, I want the major gridlines
to be slightly darker than the minor ones.

However, using the syntax below, I can only seem to set the properties of one of the sets of gridlines at a
time. If I comment out the ax.xaxis.grid() call for the minor grid, the major grid color gets set correctly.
However, if I try to set both, as shown below, only the color for the minor grid is set.

Is the minor grid overriding the major grid somehow? If so, is there another property I need to set somewhere?

Many thanks if anyone can help :slight_smile:

     minor_grid_color = '#E6E6E6'
     major_grid_color = '#DCDCDC'

     figure(figsize=(pagewidth, pageheight), frameon=frameon, facecolor=facecolor, edgecolor=edgecolor)

     minor_multiple = 900
     major_multiple = 3600

     axes([0.05, 0.05, 0.90, 0.90])
     ax=gca()
     ax.xaxis.set_minor_locator(MultipleLocator(minor_multiple))
     ax.xaxis.set_major_locator(MultipleLocator(major_multiple))
     ax.xaxis.grid(True, which="major", linestyle='-', color=major_grid_color)
     ax.xaxis.grid(True, which="minor", linestyle='-', color=minor_grid_color)

I ended up finding a solution to this by using a FixedLocator and
manually setting each of the tick

positions for both major and minor grids without overlap.

I’m not sure if this is the recommended way to do this, but hey, it
worked :wink:

` for tick in range(seconds+1)[1:]:

    if tick % major_multiple ==

0:

xmajorticks.append(tick)

    elif tick % minor_multiple ==

0:

xminorticks.append(tick)

ax.xaxis.set_major_locator(FixedLocator(xmajorticks))

ax.xaxis.set_minor_locator(FixedLocator(xminorticks))

`At 15:14 14.3.2007, Peter Buschman wrote:

···

Hello:

I am trying to set different colors for both major and minor

gridlines. In essence, I want the major gridlines

to be slightly darker than the minor ones.

However, using the syntax below, I can only seem to set the

properties of one of the sets of gridlines at a

time. If I comment out the ax.xaxis.grid() call for the minor grid,

the major grid color gets set correctly.

However, if I try to set both, as shown below, only the color for the

minor grid is set.

Is the minor grid overriding the major grid somehow? If so, is
there

another property I need to set somewhere?

Many thanks if anyone can help :slight_smile:

 minor_grid_color    =

#E6E6E6

 major_grid_color    =

#DCDCDC

 figure(figsize=(pagewidth, pageheight),

frameon=frameon,

facecolor=facecolor, edgecolor=edgecolor)

 minor_multiple = 900

 major_multiple = 3600


 axes([0.05, 0.05, 0.90, 0.90])

 ax=gca()

ax.xaxis.set_minor_locator(MultipleLocator(minor_multiple))

ax.xaxis.set_major_locator(MultipleLocator(major_multiple))

 ax.xaxis.grid(True, which="major",

linestyle=‘-’, color=major_grid_color)

 ax.xaxis.grid(True, which="minor",

linestyle=‘-’, color=minor_grid_color)


Take Surveys. Earn Cash. Influence the Future of IT

Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your

opinions on IT & business topics through brief surveys-and earn
cash


http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net


https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Peter Buschman-2 wrote:

I ended up finding a solution to this by using a FixedLocator and
manually setting each of the tick
positions for both major and minor grids without overlap.

I'm not sure if this is the recommended way to do this, but hey, it worked
:wink:

     for tick in range(seconds+1)[1:]:
         if tick % major_multiple == 0:
             xmajorticks.append(tick)
         elif tick % minor_multiple == 0:
             xminorticks.append(tick)

     ax.xaxis.set_major_locator(FixedLocator(xmajorticks))
     ax.xaxis.set_minor_locator(FixedLocator(xminorticks))

Hi there,
I know this is an old post, but I'm also trying to do something similar, but
using different linestyles for the major and minor grids.

Has anyone figured out code that's more efficient than this? It seems that
this can slow down my application's data "load time". Also, since I'm using
the zoom widget, I'm not certain if this will work if the tick markers
change If I change my x limits... Any thoughts?

···

-----
Krishna Adrianto Pribadi
Test Engineer
Harley-Davidson Motor Co.
Talladega Test Facility
Vehicle Test Stands
--
View this message in context: http://old.nabble.com/Setting-color-of-both-major-and-minor-gridlines--tp9475256p28367421.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Hi Krishna,

I'm not sure about using FixedLocator if you want to zoom ...
What about the following approach:

from matplotlib import pyplot as plt
ax = plt.subplot(111, autoscale_on=False, xlim=(10, 1000), ylim=(10, 1000))
ax.set_xscale('log')
ax.set_yscale('log')
ax.grid(which='major', linestyle='-', color='blue')
ax.grid(which='minor', linestyle='--', color='red')
plt.show()

Kind regards,
Matthias

···

On Monday 26 April 2010 18:59:41 KrishnaPribadi wrote:

Peter Buschman-2 wrote:
> I ended up finding a solution to this by using a FixedLocator and
> manually setting each of the tick
> positions for both major and minor grids without overlap.
>
> I'm not sure if this is the recommended way to do this, but hey, it
> worked :wink:
>
> for tick in range(seconds+1)[1:]:
> if tick % major_multiple == 0:
> xmajorticks.append(tick)
> elif tick % minor_multiple == 0:
> xminorticks.append(tick)
>
> ax.xaxis.set_major_locator(FixedLocator(xmajorticks))
> ax.xaxis.set_minor_locator(FixedLocator(xminorticks))

Hi there,
I know this is an old post, but I'm also trying to do something similar,
but using different linestyles for the major and minor grids.

Has anyone figured out code that's more efficient than this? It seems that
this can slow down my application's data "load time". Also, since I'm using
the zoom widget, I'm not certain if this will work if the tick markers
change If I change my x limits... Any thoughts?