Skip to content

Commit 49677f1

Browse files
committed
rolled back some log changes
svn path=/trunk/matplotlib/; revision=929
1 parent 82e9239 commit 49677f1

File tree

5 files changed

+71
-25
lines changed

5 files changed

+71
-25
lines changed

TODO

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,3 +672,12 @@ square). All displayed area is white.
672672

673673
- button to add text labels easily anywhere on the plot. A few drawing
674674
buttons as well for simple things? Circle/ellipse, box, arrows, etc.
675+
676+
- toggle log/linear shows strange accumulation of ticks on y axis
677+
678+
from pylab import *
679+
x = arange(-2.00, 10, 0.01)
680+
y = exp(-x)
681+
plot(x,y)
682+
#set(gca(), xscale='log')
683+
show()

lib/matplotlib/axes.py

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,8 @@ def add_line(self, l):
698698
l.get_transform(), zip(xdata, ydata))
699699
xdata, ydata = zip(*xys)
700700

701-
corners = ( (amin(xdata), amin(ydata)), (amax(xdata), amax(ydata)) )
702-
703-
self.update_datalim(corners)
704-
701+
self.update_datalim( zip(xdata, ydata) )
702+
705703
self.lines.append(l)
706704

707705
def _get_verts_in_data_coords(self, trans, xys):
@@ -3054,19 +3052,17 @@ def set_xscale(self, value, basex = 10, subsx=None):
30543052
for patch in self.patches:
30553053
xs.extend([x for x,y in patch.get_verts()])
30563054
for collection in self.collections:
3057-
xs.extend([x for x,y in collection.get_verts()])
3055+
xs.extend([x for x,y in collection.get_verts()])
30583056
posx = [x for x in xs if x>0]
3059-
minx = min(posx)
3060-
maxx = max(posx)
3061-
# warning, probably breaks inverted axis
3062-
self.set_xlim((0.1*minx, maxx))
3063-
3064-
3065-
3057+
if len(posx):
3058+
minx = min(posx)
3059+
maxx = max(posx)
3060+
# warning, probably breaks inverted axis
3061+
self.set_xlim((0.1*minx, maxx))
3062+
30663063
self.xaxis.set_major_locator(LogLocator(basex))
30673064
self.xaxis.set_major_formatter(LogFormatterMathtext(basex))
3068-
self.xaxis.set_minor_locator(LogLocator(basex,subsx))
3069-
3065+
self.xaxis.set_minor_locator(LogLocator(basex,subsx))
30703066
self.transData.get_funcx().set_type(LOG10)
30713067
elif value == 'linear':
30723068
self.xaxis.set_major_locator(AutoLocator())
@@ -3154,10 +3150,12 @@ def set_yscale(self, value, basey=10, subsy=None):
31543150
for collection in self.collections:
31553151
ys.extend([y for x,y in collection.get_verts()])
31563152
posy = [y for y in ys if y>0]
3157-
miny = min(posy)
3158-
maxy = max(posy)
3159-
# warning, probably breaks inverted axis
3160-
self.set_ylim((0.1*miny, maxy))
3153+
if len(posy):
3154+
miny = min(posy)
3155+
maxy = max(posy)
3156+
# warning, probably breaks inverted axis
3157+
self.set_ylim((0.1*miny, maxy))
3158+
31613159

31623160
self.yaxis.set_major_locator(LogLocator(basey))
31633161
self.yaxis.set_major_formatter(LogFormatterMathtext(basey))
@@ -3422,7 +3420,12 @@ def text(self, x, y, s, fontdict=None, **kwargs):
34223420
return t
34233421

34243422

3425-
3423+
def toggle_log_lineary(self):
3424+
'toggle between log and linear on the y axis'
3425+
funcy = self.transData.get_funcy().get_type()
3426+
if funcy==LOG10: self.set_yscale('linear')
3427+
elif funcy==IDENTITY: self.set_yscale('log')
3428+
34263429
def vlines(self, x, ymin, ymax, color='k'):
34273430
"""\
34283431
VLINES(x, ymin, ymax, color='k')
@@ -3957,7 +3960,11 @@ def get_xscale(self):
39573960
def get_yscale(self):
39583961
'return the yaxis scale string'
39593962
return 'polar'
3960-
3963+
3964+
def toggle_log_lineary(self):
3965+
'toggle between log and linear axes ignored for polar'
3966+
pass
3967+
39613968
class PolarSubplot(SubplotBase, PolarAxes):
39623969
"""
39633970
Create a polar subplot with
@@ -3976,3 +3983,30 @@ def __init__(self, fig, *args, **kwargs):
39763983
SubplotBase.__init__(self, *args)
39773984
PolarAxes.__init__(self, fig, [self.figLeft, self.figBottom, self.figW, self.figH], **kwargs)
39783985

3986+
3987+
"""
3988+
# this is some discarded code I was using to find the minimum positive
3989+
# data point for some log scaling fixes. I realized there was a
3990+
# cleaner way to do it, but am keeping this around as an example for
3991+
# how to get the data out of the axes. Might want to make something
3992+
# like this a method one day, or better yet make get_verts and Artist
3993+
# method
3994+
3995+
minx, maxx = self.get_xlim()
3996+
if minx<=0 or maxx<=0:
3997+
# find the min pos value in the data
3998+
xs = []
3999+
for line in self.lines:
4000+
xs.extend(line.get_xdata())
4001+
for patch in self.patches:
4002+
xs.extend([x for x,y in patch.get_verts()])
4003+
for collection in self.collections:
4004+
xs.extend([x for x,y in collection.get_verts()])
4005+
posx = [x for x in xs if x>0]
4006+
if len(posx):
4007+
4008+
minx = min(posx)
4009+
maxx = max(posx)
4010+
# warning, probably breaks inverted axis
4011+
self.set_xlim((0.1*minx, maxx))
4012+
"""

lib/matplotlib/backend_bases.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,9 @@ def key_press(self, event):
812812
if event.key == 'g':
813813
event.inaxes.grid()
814814
self.canvas.draw()
815+
if event.key == 'l':
816+
event.inaxes.toggle_log_lineary()
817+
self.canvas.draw()
815818

816819

817820
# cursors

lib/matplotlib/ticker.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,12 +638,11 @@ def __call__(self):
638638
def autoscale(self):
639639
'Try to choose the view limits intelligently'
640640
self.verify_intervals()
641+
641642
vmin, vmax = self.dataInterval.get_bounds()
642643
if vmax<vmin:
643644
vmin, vmax = vmax, vmin
644645

645-
646-
647646
if not is_decade(vmin,self.base): vmin = decade_down(vmin,self.base)
648647
if not is_decade(vmax,self.base): vmax = decade_up(vmax,self.base)
649648
if vmin==vmax:

src/_transforms.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Point::~Point()
132132
}
133133

134134
Interval::Interval(LazyValue* val1, LazyValue* val2) :
135-
_val1(val1), _val2(val2) {
135+
_val1(val1), _val2(val2){
136136
_VERBOSE("Interval::Interval");
137137
Py_INCREF(val1);
138138
Py_INCREF(val2);
@@ -170,7 +170,6 @@ Interval::update(const Py::Tuple &args) {
170170

171171
for (size_t i=0; i<Nval; ++i) {
172172
thisval = Py::Float(vals[i]);
173-
174173
if (thisval<minx) minx = thisval;
175174
if (thisval>maxx) maxx = thisval;
176175
}
@@ -183,6 +182,7 @@ Interval::update(const Py::Tuple &args) {
183182

184183
Bbox::Bbox(Point* ll, Point* ur) : _ll(ll), _ur(ur) {
185184
_VERBOSE("Bbox::Bbox");
185+
186186
Py_INCREF(ll);
187187
Py_INCREF(ur);
188188
};
@@ -382,7 +382,7 @@ Bbox::update(const Py::Tuple &args) {
382382
if (x>maxx) maxx=x;
383383
if (y<miny) miny=y;
384384
if (y>maxy) maxy=y;
385-
385+
386386
}
387387

388388

@@ -1465,6 +1465,7 @@ Interval::init_type()
14651465
add_varargs_method("span", &Interval::span, "span()\n");
14661466
add_varargs_method("val1", &Interval::val1, "val1()\n");
14671467
add_varargs_method("val2", &Interval::val2, "val2()\n");
1468+
14681469
}
14691470

14701471
void

0 commit comments

Comments
 (0)