Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e8ce81

Browse files
committed
First pass at symmetrical log plots. Expose xscale() and yscale()
through pyplot. svn path=/branches/transforms/; revision=4733
1 parent 3abab34 commit 2e8ce81

5 files changed

Lines changed: 299 additions & 58 deletions

File tree

examples/symlog_demo.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
from pylab import *
3+
4+
dt = 1.0
5+
x = arange(-50.0, 50.0, dt)
6+
y = arange(0, 100.0, dt)
7+
8+
subplot(311)
9+
plot(x, y)
10+
xscale('symlog')
11+
ylabel('symlogx')
12+
grid(True)
13+
gca().xaxis.grid(True, which='minor') # minor grid on too
14+
15+
subplot(312)
16+
plot(y, x)
17+
yscale('symlog')
18+
ylabel('symlogy')
19+
20+
21+
subplot(313)
22+
plot(x, npy.sin(x / 3.0))
23+
xscale('symlog')
24+
yscale('symlog')
25+
grid(True)
26+
ylabel('symlog both')
27+
28+
savefig('log_demo')
29+
show()

lib/matplotlib/axes.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,6 @@ def cla(self):
741741

742742
self.xaxis.cla()
743743
self.yaxis.cla()
744-
self.set_xscale('linear')
745-
self.set_yscale('linear')
746744

747745
self.ignore_existing_data_limits = True
748746
self.callbacks = cbook.CallbackRegistry(('xlim_changed', 'ylim_changed'))
@@ -768,6 +766,8 @@ def cla(self):
768766
self.collections = [] # collection.Collection instances
769767

770768
self._autoscaleon = True
769+
self.set_xscale('linear')
770+
self.set_yscale('linear')
771771

772772
self.grid(self._gridOn)
773773
props = font_manager.FontProperties(size=rcParams['axes.titlesize'])
@@ -1654,6 +1654,7 @@ def get_xscale(self):
16541654
", ".join(mscale.get_scale_names()))
16551655
return self.xaxis.get_scale()
16561656

1657+
# MGDTODO: Update docstring
16571658
def set_xscale(self, value, **kwargs):
16581659
"""
16591660
SET_XSCALE(value)
@@ -1673,6 +1674,7 @@ def set_xscale(self, value, **kwargs):
16731674
ACCEPTS: [%(scale)s]
16741675
""" % {'scale': ' | '.join([repr(x) for x in mscale.get_scale_names()])}
16751676
self.xaxis.set_scale(value, **kwargs)
1677+
self.autoscale_view()
16761678
self._update_transScale()
16771679

16781680
def get_xticks(self, minor=False):
@@ -1833,6 +1835,7 @@ def set_yscale(self, value, **kwargs):
18331835
ACCEPTS: %(scale)s
18341836
""" % {'scale': ' | '.join([repr(x) for x in mscale.get_scale_names()])}
18351837
self.yaxis.set_scale(value, **kwargs)
1838+
self.autoscale_view()
18361839
self._update_transScale()
18371840

18381841
def get_yticks(self, minor=False):
@@ -1992,6 +1995,7 @@ def start_pan(self, x, y, button):
19921995
lim = self.viewLim.frozen(),
19931996
trans = self.transData.frozen(),
19941997
trans_inverse = self.transData.inverted().frozen(),
1998+
bbox = self.bbox.frozen(),
19951999
x = x,
19962000
y = y
19972001
)
@@ -2044,9 +2048,11 @@ def format_deltas(key, dx, dy):
20442048
p = self._pan_start
20452049
dx = x - p.x
20462050
dy = y - p.y
2051+
if dx == 0 and dy == 0:
2052+
return
20472053
if button == 1:
20482054
dx, dy = format_deltas(key, dx, dy)
2049-
result = self.bbox.frozen().translated(-dx, -dy) \
2055+
result = p.bbox.translated(-dx, -dy) \
20502056
.transformed(p.trans_inverse)
20512057
elif button == 3:
20522058
try:

lib/matplotlib/pyplot.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from matplotlib.axes import Axes
1313
from matplotlib.projections import PolarAxes
1414
from matplotlib import mlab # for csv2rec in plotfile
15+
from matplotlib.scale import get_scale_names
1516

1617
from matplotlib import cm
1718
from matplotlib.cm import get_cmap
@@ -726,6 +727,30 @@ def ylim(*args, **kwargs):
726727
return ret
727728

728729

730+
# MGDTODO: Update docstring
731+
def xscale(*args, **kwargs):
732+
"""
733+
SET_XSCALE(value)
734+
735+
Set the xscaling: %(scale)s
736+
""" % {'scale': ' | '.join([repr(x) for x in get_scale_names()])}
737+
ax = gca()
738+
ret = ax.set_xscale(*args, **kwargs)
739+
draw_if_interactive()
740+
return ret
741+
742+
743+
# MGDTODO: Update docstring
744+
def yscale(*args, **kwargs):
745+
"""
746+
SET_YSCALE(value)
747+
748+
Set the yscaling: %(scale)s
749+
""" % {'scale': ' | '.join([repr(x) for x in get_scale_names()])}
750+
ax = gca()
751+
ret = ax.set_yscale(*args, **kwargs)
752+
draw_if_interactive()
753+
return ret
729754

730755

731756
def xticks(*args, **kwargs):

0 commit comments

Comments
 (0)