RE : [Matplotlib-users] Log plot in base b?

Hi, I though about this too and your message has convinced me it was
worth spending a few minutes adding this :wink:
I just patched loglocator and logformater to be able to use arbitrary
base, and also to use arbitrary "minor" ticks. Well, I put minor between
quotes because Logticker do not really use minor ticks, only discard
label for ticks that are not integer exponents of base...
Usage is like this:
Semilogx(x,y)

#compatible with previous usage
gca().set_xscale('log')
# major tick every 10**i, minor tick every range(2,10)*10**I

#change base
gca().set_xscale('log',base=16)
#Major tick every 16**i, minor tick every range(2,16)*16**i

#full control
gca().set_xscale('log',base=100,subs=[10,20,50])
#Major tick every 16**i, minor tick every subs*16**i

This gives me all the flexibility I need, and I feel it is a step in the
right direction, but:
-maybe a rework of log ticker is needed so that it use minor/major tick
mechanism? Current mechanism is not as clean as it could, imho
-maybe autoscale for loglocator should adjust the base/range to avoid
excessive ticking (A discussion I had with john, with a zoom out it is
possible to have very dense ticking)...Not so easy to do though, as subs
has to be adjusted too if one does not want too many minor ticks, as
this adjustment is not so easy to do if one want "usefull" minor ticks
in logscale...
I thing these 2 points are linked, I would not go to 2 if 1 is not done,
but if one is done (using some kind of linear locator (with autoscale
capability) on 1 decade for minor ticks, and repeat this minor tick on
each decade as I have done with my subs, I think we can have a very nice
framework to have fully automatic and nicely configurable log ticking
:slight_smile:

Best regards,

Greg.

PS: the 2 modified files are included, I made my modif relative to
CVS...

ticker.py (26.8 KB)

axes.py (73.7 KB)

路路路

-----Message d'origine-----
De : matplotlib-users-admin@lists.sourceforge.net
[mailto:matplotlib-users-admin@lists.sourceforge.net] De la
part de Dominique Orban
Envoy茅 : mardi 17 ao没t 2004 18:57
脌 : matplotlib-users@lists.sourceforge.net
Objet : [Matplotlib-users] Log plot in base b?

Hi,

What would be the easiest way, in matplotlib, to achieve log scaling,
along the x axis, say, in a base other than 10? I see in axes.py that
semilog[xy] have LOG10 hardwired. I am using matplotlib 0.60.2.

Thanks,
Dominique

-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on
Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic
DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free
Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridge> s/9_108_r285

_______________________________________________

Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Great, this is doing the job nicely, thanks ! I am not very clear as to what the 'subs' argument really does. In your example:

> #full control
> gca().set_xscale('log',base=100,subs=[10,20,50])
> #Major tick every 16**i, minor tick every subs*16**i

(16 should be 100 right?). There's a major tick at 100, 100^2, 100^3, etc. And you're saying there are minor tick marks at 10*100*i ?!?

What if you'd want tick labels [0, 1, 2, 3, 4, ...] instead of (in base 2, say) [1, 2, 4, 8, 16, ...] ? Is that easily done? I tried to obtain it based on the example custom_ticker1.py (in the examples subdirectory), but haven't been successful so far.

Thanks A LOT for the update of axes.py and ticker.py,
Dominique

Gregory Lielens wrote:

路路路

Hi, I though about this too and your message has convinced me it was
worth spending a few minutes adding this :wink:
I just patched loglocator and logformater to be able to use arbitrary
base, and also to use arbitrary "minor" ticks. Well, I put minor between
quotes because Logticker do not really use minor ticks, only discard
label for ticks that are not integer exponents of base...
Usage is like this:
Semilogx(x,y)

#compatible with previous usage
gca().set_xscale('log') # major tick every 10**i, minor tick every range(2,10)*10**I

#change base
gca().set_xscale('log',base=16)
#Major tick every 16**i, minor tick every range(2,16)*16**i

#full control
gca().set_xscale('log',base=100,subs=[10,20,50])
#Major tick every 16**i, minor tick every subs*16**i

This gives me all the flexibility I need, and I feel it is a step in the
right direction, but:
-maybe a rework of log ticker is needed so that it use minor/major tick
mechanism? Current mechanism is not as clean as it could, imho
-maybe autoscale for loglocator should adjust the base/range to avoid
excessive ticking (A discussion I had with john, with a zoom out it is
possible to have very dense ticking)...Not so easy to do though, as subs
has to be adjusted too if one does not want too many minor ticks, as
this adjustment is not so easy to do if one want "usefull" minor ticks
in logscale...
I thing these 2 points are linked, I would not go to 2 if 1 is not done,
but if one is done (using some kind of linear locator (with autoscale
capability) on 1 decade for minor ticks, and repeat this minor tick on
each decade as I have done with my subs, I think we can have a very nice
framework to have fully automatic and nicely configurable log ticking
:slight_smile:

Best regards,

Greg.

PS: the 2 modified files are included, I made my modif relative to
CVS...

-----Message d'origine-----
De : matplotlib-users-admin@lists.sourceforge.net [mailto:matplotlib-users-admin@lists.sourceforge.net] De la part de Dominique Orban
Envoy茅 : mardi 17 ao没t 2004 18:57
脌 : matplotlib-users@lists.sourceforge.net
Objet : [Matplotlib-users] Log plot in base b?

Hi,

What would be the easiest way, in matplotlib, to achieve log scaling, along the x axis, say, in a base other than 10? I see in axes.py that semilog[xy] have LOG10 hardwired. I am using matplotlib 0.60.2.

Thanks,
Dominique

Great, this is doing the job nicely, thanks ! I am not very clear as to
what the 'subs' argument really does. In your example:

> #full control
> gca().set_xscale('log',base=100,subs=[10,20,50])
> #Major tick every 16**i, minor tick every subs*16**i

(16 should be 100 right?).

oooouuuups, yes indeed, sorry!

There's a major tick at 100, 100^2, 100^3,
etc. And you're saying there are minor tick marks at 10*100*i ?!?

hum, not really, minor tick every array([10,20,50])*100**i (I use array
else python (and maybe some reader too familiar with python lists) may
think I mean [10,20,50] concatenated 100**i with itself...that could be
a very long list indeed :wink: )...
So minor ticks at
...0.001,0.002,0.005,0.1,0.2,0.5,10,20,50,1000,2000,5000,...

What if you'd want tick labels [0, 1, 2, 3, 4, ...] instead of (in base
2, say) [1, 2, 4, 8, 16, ...] ?
Is that easily done? I tried to obtain
it based on the example custom_ticker1.py (in the examples
subdirectory), but haven't been successful so far.

You mean tick labels like a linear plot, but with log ticking? (and
beware of 0, I doubt you will be able to see the 0 label in a log plot
except if you do a *LOT* of paning :wink: :stuck_out_tongue_winking_eye: )
If yes, this is not yet possible, because only "major" ticks (the one
corresponding to base**i) are labeled, and what you want is labeling of
all ticks...this would be feasible when I cleanup minor/major ticking
for logscale, in the meantime I added a flag to logformatter to tell
"label all ticks" instead of "label only major ticks".
Then, to do what you want (or what I believe you want :wink: ),
simply do
gca().set_xscale('log',base=1000,label_minor=True).

the base should be large enough so that your whole xrange is in it, and
by default minor tick will be generated every unit.
Be aware though that due to log spacing, last labels could be very close
to each other and this ain't pretty :wink: That's why I allowed full
control on minor ticks with subs, often you do want to carefully choose
which ticks you want, because you can end up with a black mes of ticks
and labels on the right of your graph if you don't...

Thanks A LOT for the update of axes.py and ticker.py,

you're welcome,

Greg.

路路路

On Wed, 2004-08-18 at 21:45, Dominique Orban wrote: