SourceForge logo
SourceForge logo
Menu

matplotlib-users — Discussion related to using matplotlib

You can subscribe to this list here.

2003 Jan
Feb
Mar
Apr
May
(3)
Jun
Jul
Aug
(12)
Sep
(12)
Oct
(56)
Nov
(65)
Dec
(37)
2004 Jan
(59)
Feb
(78)
Mar
(153)
Apr
(205)
May
(184)
Jun
(123)
Jul
(171)
Aug
(156)
Sep
(190)
Oct
(120)
Nov
(154)
Dec
(223)
2005 Jan
(184)
Feb
(267)
Mar
(214)
Apr
(286)
May
(320)
Jun
(299)
Jul
(348)
Aug
(283)
Sep
(355)
Oct
(293)
Nov
(232)
Dec
(203)
2006 Jan
(352)
Feb
(358)
Mar
(403)
Apr
(313)
May
(165)
Jun
(281)
Jul
(316)
Aug
(228)
Sep
(279)
Oct
(243)
Nov
(315)
Dec
(345)
2007 Jan
(260)
Feb
(323)
Mar
(340)
Apr
(319)
May
(290)
Jun
(296)
Jul
(221)
Aug
(292)
Sep
(242)
Oct
(248)
Nov
(242)
Dec
(332)
2008 Jan
(312)
Feb
(359)
Mar
(454)
Apr
(287)
May
(340)
Jun
(450)
Jul
(403)
Aug
(324)
Sep
(349)
Oct
(385)
Nov
(363)
Dec
(437)
2009 Jan
(500)
Feb
(301)
Mar
(409)
Apr
(486)
May
(545)
Jun
(391)
Jul
(518)
Aug
(497)
Sep
(492)
Oct
(429)
Nov
(357)
Dec
(310)
2010 Jan
(371)
Feb
(657)
Mar
(519)
Apr
(432)
May
(312)
Jun
(416)
Jul
(477)
Aug
(386)
Sep
(419)
Oct
(435)
Nov
(320)
Dec
(202)
2011 Jan
(321)
Feb
(413)
Mar
(299)
Apr
(215)
May
(284)
Jun
(203)
Jul
(207)
Aug
(314)
Sep
(321)
Oct
(259)
Nov
(347)
Dec
(209)
2012 Jan
(322)
Feb
(414)
Mar
(377)
Apr
(179)
May
(173)
Jun
(234)
Jul
(295)
Aug
(239)
Sep
(276)
Oct
(355)
Nov
(144)
Dec
(108)
2013 Jan
(170)
Feb
(89)
Mar
(204)
Apr
(133)
May
(142)
Jun
(89)
Jul
(160)
Aug
(180)
Sep
(69)
Oct
(136)
Nov
(83)
Dec
(32)
2014 Jan
(71)
Feb
(90)
Mar
(161)
Apr
(117)
May
(78)
Jun
(94)
Jul
(60)
Aug
(83)
Sep
(102)
Oct
(132)
Nov
(154)
Dec
(96)
2015 Jan
(45)
Feb
(138)
Mar
(176)
Apr
(132)
May
(119)
Jun
(124)
Jul
(77)
Aug
(31)
Sep
(34)
Oct
(22)
Nov
(23)
Dec
(9)
2016 Jan
(26)
Feb
(17)
Mar
(10)
Apr
(8)
May
(4)
Jun
(8)
Jul
(6)
Aug
(5)
Sep
(9)
Oct
(4)
Nov
Dec
2017 Jan
(5)
Feb
(7)
Mar
(1)
Apr
(5)
May
Jun
(3)
Jul
(6)
Aug
(1)
Sep
Oct
(2)
Nov
(1)
Dec
2018 Jan
Feb
Mar
Apr
(1)
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2020 Jan
Feb
Mar
Apr
May
(1)
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2025 Jan
(1)
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
S M T W T F S


1
(14)
2
(22)
3
(8)
4
(10)
5
(1)
6
7
(11)
8
(4)
9
(14)
10
(18)
11
(18)
12
(2)
13
(8)
14
(14)
15
(6)
16
(8)
17
(9)
18
(9)
19
(7)
20
(8)
21
(8)
22
(14)
23
(10)
24
(11)
25
(17)
26
(1)
27
(3)
28
(12)





Showing 1 results of 1

From: Darren D. <dd...@co...> - 2005年02月26日 20:12:42
On Friday 25 February 2005 08:45 am, Darren Dale wrote:
> On Thursday 24 February 2005 11:02 pm, John Hunter wrote:
> > >>>>> "Hans" == Hans Fangohr <H.F...@so...> writes:
> >
> > Hans> x=pylab.arange(0,1e-8,1e-9)+1.0 pylab.plot(x) pylab.show()
> >
> > Hans> All works fine when I subtract the mean of x but there seems
> > Hans> to be a problem with labelling axes for plotted data which
> > Hans> is not close to zero but shows only small variations.
> >
> > I agree it's a bug. It's not immediately clear to me what the labels
> > should be though
> >
> > 1.0000000002
> > 1.0000000004
> > 1.0000000006
> >
> > and so on? That takes up a lot of room. Granted, correct but ugly
> > is better than incorrect but pretty, but I'm curious if there is a
> > better way to format these cases. Perhaps ideal would be an indicator
> > at the bottom or top of the y axis that read '1+' and then use 2e-9,
> > 4e-9, etc as the actual tick labels. Do you agree this is ideal?
I worked on a new formatter yesterday and today. It includes the indicator 
that John described above, right now in the last ticklabel at the top of the 
axis. This custom formatter also includes scientific notation in the last 
ticklabel only. The ultimate goal is to have scientific notation be formatted 
like in the logplots, but I havent gotten that far yet.
Using the offset makes a large ticklabel at the moment. You can pass 
useOffset=False to ScalarFormatterScientific to turn this feature off (see end 
of script below). Interested parties, please give this script a whirl and send 
me your comments.
(John, I have now subclassed ScalarFormatter, I didnt realize I had altered 
a method that other formatters were inheriting.)
Darren
from matplotlib import *
rc('font',size='smaller')
rc('tick',labelsize='smaller')
from matplotlib.ticker import ScalarFormatter, LinearLocator
import math
from matplotlib.numerix import absolute, average
from pylab import *
class ScalarFormatterScientific(ScalarFormatter):
 """
 Tick location is a plain old number. If viewInterval is set, the
 formatter will use %d, %1.#f or %1.ef as appropriate. If it is
 not set, the formatter will do str conversion
 """
 def __init__(self, useOffset=True):
 """
 useOffset allows plotting small data ranges with large offsets:
 for example: [1+1e-9,1+2e-9,1+3e-9]
 """
 self._useOffset = useOffset
 
 def set_locs(self, locs):
 self.locs = locs
 self._set_offset()
 self._set_orderOfMagnitude()
 self._set_format()
 
 def _set_offset(self):
 # offset of 20,001 is 20,000, for example
 if self._useOffset:
 ave_loc = average(self.locs)
 std_loc = std(self.locs)
 if ave_loc: # dont want to take log10(0)
 ave_oom = math.floor(math.log10(absolute(ave_loc)))
 if std_loc/math.fabs(ave_loc) < 1e-4: # four sig-figs
 # add 1e-15 because of floating point precision, fixes conversion
 self.offset = int(ave_loc/10**ave_oom+1e-15)*10**ave_oom
 else: self.offset = 0
 
 def _set_orderOfMagnitude(self):
 # if using an offset, oom applies after applying the offset
 locs = array(self.locs)-self.offset
 ave_loc_abs = average(absolute(locs))
 oom = math.floor(math.log10(ave_loc_abs))
 # need to special-case for range of 0-1e-5
 if oom <= 0 and std(locs) < 1e-4:#10**(2*oom):
 self.orderOfMagnitude = oom
 elif oom <=0 and oom >= -5:
 pass
 elif math.fabs(oom) >= 4:
 self.orderOfMagnitude = oom
 
 def _set_format(self):
 locs = (array(self.locs,'d')-self.offset) / \
 10**self.orderOfMagnitude+1e-15
 sigfigs = [len(str('%1.4f'% loc).split('.')[1].rstrip('0')) \
 for loc in locs]
 sigfigs.sort()
 self.format = '%1.' + str(sigfigs[-1]) + 'f'
 
 def pprint_val(self, x, d):
 xp = (x-self.offset)/10**self.orderOfMagnitude
 if x==self.locs[-1] and (self.orderOfMagnitude or self.offset):
 offsetStr = ''
 sciNotStr = ''
 xp = self.format % xp
 if self.offset: 
 p = '%1.e+'% self.offset
 offsetStr = self._formatSciNotation(p)
 if self.orderOfMagnitude: 
 p = 'x%1.e'% 10**self.orderOfMagnitude
 sciNotStr = self._formatSciNotation(p)
 return ''.join((offsetStr,xp,sciNotStr))
 elif xp==0: return '%d'% xp
 else: return self.format % xp
 
 def _formatSciNotation(self,s):
 tup = s.split('e')
 mantissa = tup[0]
 sign = tup[1][0].replace('+', '')
 exponent = tup[1][1:].lstrip('0')
 return '%se%s%s' %(mantissa, sign, exponent)
 
figure(1,figsize=(6,6))
ax1 = axes([.2,.74,.75,.2])
ax1.plot(arange(11)*5e2)
ax1.yaxis.set_major_formatter(ScalarFormatterScientific())
ax1.xaxis.set_visible(False)
ax1.set_title('BIG NUMBERS',fontsize=14)
ax2 = axes([.2,.51,.75,.2])
ax2.plot(arange(11)*1e4)
ax2.yaxis.set_major_formatter(ScalarFormatterScientific())
ax2.text(1,6e4,'6e4')
ax2.xaxis.set_visible(False)
ax3 = axes([.2,.28,.75,.2])
ax3.plot(arange(11)*1e4+1e10)
ax3.yaxis.set_major_formatter(ScalarFormatterScientific())
ax3.text(1,6e4+1e10,'1e10+6e4')
ax3.xaxis.set_visible(False)
ax4 = axes([.2,.05,.75,.2])
ax4.plot(arange(11)*1e4+1e10)
ax4.yaxis.set_major_formatter(ScalarFormatterScientific(useOffset=False))
ax4.text(1,1e10+6e4,'same as above, no offset')
figure(2,figsize=(6,6))
ax1 = axes([.225,.74,.75,.2])
ax1.plot(arange(11)*5e-5)
ax1.yaxis.set_major_formatter(ScalarFormatterScientific())
ax1.xaxis.set_visible(False)
ax1.set_title('small numbers',fontsize=8)
ax2 = axes([.225,.51,.75,.2])
ax2.plot(arange(11)*1e-5)
ax2.yaxis.set_major_formatter(ScalarFormatterScientific())
ax2.text(1,6e-5,'6e-5')
ax2.xaxis.set_visible(False)
ax3 = axes([.225,.28,.75,.2])
ax3.plot(arange(11)*1e-10+1e-5)
ax3.yaxis.set_major_formatter(ScalarFormatterScientific())
ax3.text(1,1e-5+6e-10,'6e-10+1e-5')
ax3.xaxis.set_visible(False)
ax4 = axes([.225,.05,.75,.2])
ax4.plot(arange(11)*1e-10+1e-5)
ax4.yaxis.set_major_formatter(ScalarFormatterScientific(useOffset=False))
ax4.text(1,1e-5+6e-10,'same as above, no offset')
show()

Showing 1 results of 1

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 によって変換されたページ (->オリジナル) /