SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: per f. <per...@gm...> - 2009年02月28日 21:52:13
hi all,
when i make any numeric scatter plot containing floats, the formatted tick
labels always have leading zeros, e.g "0.5" as opposed to ".5" in the
labels.
for example:
x = rand(10)
scatter(x,x)
is there any way to change this to remove the leading zeros? i have tried:
s = subplot(111)
majorFormatter = FormatStrFormatter('%0.1f')
s.xaxis.set_major_formatter(majorFormatter)
scatter(x,x)
but it does not work. i also tried "%.f" but it does not work either. the
matlab default is to plot without the leading zero and i am trying to
recreate this.
thank you.
From: Jae-Joon L. <lee...@gm...> - 2009年02月28日 23:51:09
FormatStrFormatter (and other formatters) rely on Python's string
interpolation, and It does not seem to be possible to get rid of the
leading zero (http://docs.python.org/library/stdtypes.html).
I think what you can do is to replace "0." with "." after the
interpolation. Something like below works for me.
from matplotlib.ticker import ScalarFormatter
s = subplot(111)
class ScalarFormatterNoLeadingZero(ScalarFormatter):
 def pprint_val(self, x):
 s = ScalarFormatter.pprint_val(self, x)
 return s.replace("0.",".")
s.xaxis.set_major_formatter(ScalarFormatterNoLeadingZero())
HTH,
-JJ
On Sat, Feb 28, 2009 at 4:52 PM, per freem <per...@gm...> wrote:
> hi all,
>
> when i make any numeric scatter plot containing floats, the formatted tick
> labels always have leading zeros, e.g "0.5" as opposed to ".5" in the
> labels.
>
> for example:
>
> x = rand(10)
> scatter(x,x)
>
> is there any way to change this to remove the leading zeros? i have tried:
>
> s = subplot(111)
> majorFormatter = FormatStrFormatter('%0.1f')
> s.xaxis.set_major_formatter(majorFormatter)
> scatter(x,x)
>
> but it does not work. i also tried "%.f" but it does not work either. the
> matlab default is to plot without the leading zero and i am trying to
> recreate this.
>
> thank you.
>
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
> -Strategies to boost innovation and cut costs with open source participation
> -Receive a 600ドル discount off the registration fee with the source code: SFAD
> http://p.sf.net/sfu/XcvMzF8H
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /