Matplotlib labels

Hi all,

I'm having problems with axis labels for large integers (1471674 is represented as 1000 +1.479e6) .... I really need to see the number as a conventional integer. I have the feeling that it should be possible with ticker. FormatStrFormatter but I have not been able to work out how. Any advice would be greatly appreciated.

While I'm asking stupid questions, I'd also like to know how to let the absolute dimensions of a subplot (with a barh() horizontal bar chart) adjust themselves according to the number of bars added (keeping the height of the bars strictly constant rather than the bar height adjusting according to the number of data points).

Many thanks

David

DAVID HORNER wrote:

Hi all,

I'm having problems with axis labels for large integers (1471674 is represented as 1000 +1.479e6) .... I really need to see the number as a conventional integer. I have the feeling that it should be possible with ticker. FormatStrFormatter but I have not been able to work out how. Any advice would be greatly appreciated.
  

Assuming 'ax' is your current set of axes (obtained from gca() or a call to subplot(), for example)...
   from matplotlib import ticker
  ...

  ax.xaxis.set_major_formatter(ticker.FormatStrFormatter("%d"))
  ax.yaxis.set_major_formatter(ticker.FormatStrFormatter("%d"))

While I'm asking stupid questions, I'd also like to know how to let the absolute dimensions of a subplot (with a barh() horizontal bar chart) adjust themselves according to the number of bars added (keeping the height of the bars strictly constant rather than the bar height adjusting according to the number of data points).
  

There's no direct way to do this, but by setting the figure size based on the number of bars, you should be able to fake it. You can set the overall figure size either when you create the figure:

  figure(figsize=(4,3))

or after the fact (which doesn't really work with interactive GUIs -- that is, it won't resize the window) --

  gcf().set_size_inches((4, 3))

The unit is in inches -- the dpi of the figure can also be set in a similar way.

Hope that at least helps,
Mike

···

Many thanks

David

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Michael Droettboom wrote:

or after the fact (which doesn't really work with interactive GUIs -- that is, it won't resize the window) --
  

I'll correct myself on this point. According to the docs, the window will resize if forward=True for Gtk and Wx backends.

Cheers,
Mike

···

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Hi all,

I'm having problems with axis labels for large integers (1471674 is represented as 1000 +1.479e6) .... I really need to see the number as a conventional integer. I have the feeling that it should be possible with ticker. FormatStrFormatter but I have not been able to work out how. Any advice would be greatly appreciated.

Assuming 'ax' is your current set of axes (obtained from gca() or a call to subplot(), for example)...
from matplotlib import ticker
...

ax.xaxis.set_major_formatter(ticker.FormatStrFormatter("%d"))
ax.yaxis.set_major_formatter(ticker.FormatStrFormatter("%d"))

While I'm asking stupid questions, I'd also like to know how to let the absolute dimensions of a subplot (with a barh() horizontal bar chart) adjust themselves according to the number of bars added (keeping the height of the bars strictly constant rather than the bar height adjusting according to the number of data points).

Fantastic .... I knew this should be easy

There's no direct way to do this, but by setting the figure size based on the number of bars, you should be able to fake it. You can set the overall figure size either when you create the figure:

figure(figsize=(4,3))

or after the fact (which doesn't really work with interactive GUIs -- that is, it won't resize the window) --

gcf().set_size_inches((4, 3))

The unit is in inches -- the dpi of the figure can also be set in a similar way.

Hmm, the thing is that I'm using a barh() subplot underneath a series of bar() subplots. The bar() subplots always have the same y axes, but the number of items in the barh() subplot varies (I use the barh() to illustrate features along a stretch of genomic DNA which also has quantitative values attached to it in the bar() plots above). I need to make a series of figures in this way wherein the bar() subplots always have the same dimension, but only the "height" of the barh() subplot varies (with the number of instances to plot) while the Y axes ALL need to remain the same.

Can I size the whole figure with the above and fix the dimensions of each of the subplots independently? If so I should be able to bodge it!

I'm pretty new to matplotlib and not really an expert programmer in any case. While I'm very pleased with the quality of the figures, I'm really struggling with ironing out a few maddening glitches.

Thanks again.

D

···

Hope that at least helps,
Mike

Many thanks

David

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA