Is there a maximum number of x tickmarks?

I have an issue with showing more than 81 tick marks on an X axis and I am
trying to determine a way around it. Background... I am plotting vectors in
which each element represents a different variable and I really do want to
see the labels associated with each element. The vectors may be only 8
elements long, or as much as 110. When there are more than say 40 elements,
I usually split the plot into two plots contained in a single figure window
(e.g., plotting elements 0:30 in fig.add_subplot(211) and 30:60 in
fig.add_subplot(212)).

Here are a couple of examples...

Only 41 variables:
http://old.nabble.com/file/p27924845/Factor_2_TrainingProfiles.png

71 variables:
http://old.nabble.com/file/p27924845/Factor_2_TrainingProfiles.jpeg

I have a vector with a 105 elements and before I split things into three
plots I wanted to see what cramming 53 or so variables into a single set of
axes would look like. But, my code that works for these cases does not show
enough tickmarks for the 105 element data.

Here is an example that you can copy and paste to see for yourself.

import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
fig = plt.figure(figsize=[12,7])
ax = fig.add_subplot(111)
ax.plot(range(110))
fig.canvas.draw()
ints = range(1,111)
ints = [str(num) for num in ints]
ax.xaxis.set_major_locator(MaxNLocator(110))
xtickNames = plt.setp(ax, xticklabels=ints)
plt.setp(xtickNames, rotation=90, fontsize=7);

If you play with the argument to MaxNLocator, you'll see how for smaller
values (like 40) things work as expected (or at least how I have shown the
code has worked for the smaller data sets).

I have been poking around trying to see what options I have and have not
found anything to get past this limit. Before I start diving into source
code, can anyone suggest

-Is there a limit?
-Is there an obvious way to accomplish what I need?

Ultimately, I may split large vectors like this into more than two plots but
hitting that limit has made me want to investigate why.

Thanks!

···

-----
Josh Hemann
Statistical Advisor
http://www.vni.com/ Visual Numerics
jhemann@...1899... | P 720.407.4214 | F 720.407.4199


View this message in context: http://old.nabble.com/Is-there-a-maximum-number-of-x-tickmarks--tp27924845p27924845.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Oh these busy chemical compound plots :slight_smile: Are those results of gas chromatography analysis?

Something like below produces a nice fully plotted output here. Could you give it a try?

import matplotlib.pyplot as plt
plt.plot(range(100))
locs, labels = plt.xticks(range(100), range(100))
plt.setp(labels, rotation=90, fontsize=7)
plt.show()

···

On Tue, Mar 16, 2010 at 4:37 PM, Josh Hemann <jhemann@…878…1899…> wrote:

I have an issue with showing more than 81 tick marks on an X axis and I am

trying to determine a way around it. Background… I am plotting vectors in

which each element represents a different variable and I really do want to

see the labels associated with each element. The vectors may be only 8

elements long, or as much as 110. When there are more than say 40 elements,

I usually split the plot into two plots contained in a single figure window

(e.g., plotting elements 0:30 in fig.add_subplot(211) and 30:60 in

fig.add_subplot(212)).

Here are a couple of examples…

Only 41 variables:

http://old.nabble.com/file/p27924845/Factor_2_TrainingProfiles.png

71 variables:

http://old.nabble.com/file/p27924845/Factor_2_TrainingProfiles.jpeg

I have a vector with a 105 elements and before I split things into three

plots I wanted to see what cramming 53 or so variables into a single set of

axes would look like. But, my code that works for these cases does not show

enough tickmarks for the 105 element data.

Here is an example that you can copy and paste to see for yourself.

import matplotlib.pyplot as plt

from matplotlib.ticker import MaxNLocator

fig = plt.figure(figsize=[12,7])

ax = fig.add_subplot(111)

ax.plot(range(110))

fig.canvas.draw()

ints = range(1,111)

ints = [str(num) for num in ints]

ax.xaxis.set_major_locator(MaxNLocator(110))

xtickNames = plt.setp(ax, xticklabels=ints)

plt.setp(xtickNames, rotation=90, fontsize=7);

If you play with the argument to MaxNLocator, you’ll see how for smaller

values (like 40) things work as expected (or at least how I have shown the

code has worked for the smaller data sets).

I have been poking around trying to see what options I have and have not

found anything to get past this limit. Before I start diving into source

code, can anyone suggest

-Is there a limit?

-Is there an obvious way to accomplish what I need?

Ultimately, I may split large vectors like this into more than two plots but

hitting that limit has made me want to investigate why.

Thanks!


Gökhan

Gökhan SEVER-2 wrote:

Oh these busy chemical compound plots :slight_smile: Are those results of gas
chromatography analysis?

Something like below produces a nice fully plotted output here. Could you
give it a try?

import matplotlib.pyplot as plt
plt.plot(range(100))
locs, labels = plt.xticks(range(100), range(100))
plt.setp(labels, rotation=90, fontsize=7)
plt.show()

--
Gökhan

Gokhan,

Your suggestion works great. I guess the MaxNLocator approach I have been
using will place __up__to__ N ticks but not necessarily N ticks?

And yes, these chemical profiles are from GCMS and other devices/techniques.
I added upper X axis tick labels so you know a given chemical species' name
and number; I chose to only have one legend to keep the clutter down as much
as possible; I position the upper X axis labels in or outside the plot
depending on whether the plot title exists. Luckily, I don't imagine having
to deal with more species than 105 any time soon. Thanks again! Here is the
improved plot (sorry for the pink background, I am not sure why it is
showing up that way):

http://old.nabble.com/file/p27927991/PMF2BasecaseProfiles.jpeg

···

-----
Josh Hemann
Statistical Advisor
http://www.vni.com/ Visual Numerics
jhemann at vni dizzot com


View this message in context: http://old.nabble.com/Is-there-a-maximum-number-of-x-tickmarks--tp27924845p27927991.html
Sent from the matplotlib - users mailing list archive at Nabble.com.