Skip to content

Commit 179ca0c

Browse files
committed
fixed several log tick and scaling issues
svn path=/trunk/matplotlib/; revision=333
1 parent 144cb60 commit 179ca0c

File tree

4 files changed

+60
-65
lines changed

4 files changed

+60
-65
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
New entries should be added at the top
22

3+
2004-06-07 Fixed several problems with log ticks and scaling - JDH
4+
35
2004-06-07 Fixed width/height issues for images - JDH
46

57
2004-06-03 Fixed draw_if_interactive bug for semilogx;

src/_transforms.cpp

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ Func::inverse(const Py::Tuple &args) {
326326

327327
double xout = this->inverse_api(xin);
328328
return Py::Float(xout);
329-
330329
};
331330

332331
Py::Object
@@ -977,18 +976,13 @@ Py::Object _transforms_module::new_affine (const Py::Tuple &args) {
977976

978977
}
979978

979+
980980

981-
Py::Object _transforms_module::new_identity (const Py::Tuple &args)
982-
{
983-
args.verify_length(0);
984-
return Py::Object( new Identity() );
985-
}
986-
987-
Py::Object _transforms_module::new_log (const Py::Tuple &args)
981+
Py::Object _transforms_module::new_func (const Py::Tuple &args)
988982
{
989-
args.verify_length(0);
990-
return Py::Object( new Log() );
991-
983+
args.verify_length(1);
984+
int typecode = Py::Int(args[0]);
985+
return Py::Object(new Func(typecode));
992986
}
993987

994988
Py::Object _transforms_module::new_funcxy (const Py::Tuple &args)
@@ -1004,6 +998,7 @@ Py::Object _transforms_module::new_funcxy (const Py::Tuple &args)
1004998
return Py::Object(new FuncXY(funcx, funcy));
1005999
}
10061000

1001+
10071002
Py::Object _transforms_module::new_polarxy (const Py::Tuple &args)
10081003
{
10091004
args.verify_length(0);
@@ -1113,22 +1108,13 @@ void Func::init_type()
11131108
{
11141109
behaviors().name("Func");
11151110
behaviors().doc("Map double -> double");
1111+
behaviors().supportRepr();
11161112
add_varargs_method("map", &Func::map, "map(x)\n");
11171113
add_varargs_method("inverse", &Func::inverse, "inverse(y)\n");
1114+
add_varargs_method("set_type", &Func::set_type, "set_type(TYPE)\n");
1115+
add_varargs_method("get_type", &Func::get_type, "get_type()\n");
11181116
}
11191117

1120-
void Identity::init_type()
1121-
{
1122-
behaviors().name("Identity");
1123-
behaviors().doc("Map x-> x");
1124-
}
1125-
1126-
void Log::init_type()
1127-
{
1128-
behaviors().name("Log");
1129-
behaviors().doc("Map x-> log10(x)");
1130-
}
1131-
11321118
void FuncXY::init_type()
11331119
{
11341120
behaviors().name("FuncXY");
@@ -1209,6 +1195,11 @@ DL_EXPORT(void)
12091195
_transforms = new _transforms_module;
12101196

12111197
import_array();
1198+
1199+
1200+
Py::Dict d = _transforms->moduleDictionary();
1201+
d["LOG10"] = Py::Int((int)Func::LOG10);
1202+
d["IDENTITY"] = Py::Int((int)Func::IDENTITY);
12121203
};
12131204

12141205

src/_transforms.h

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -308,47 +308,54 @@ class Bbox: public Py::PythonExtension<Bbox> {
308308
//double. Also can serve as a lazy value evaluator
309309
class Func : public Py::PythonExtension<Func> {
310310
public:
311-
311+
Func( unsigned int type=IDENTITY ) : _type(type) {};
312312
static void init_type(void);
313313

314+
Py::Object str() { return Py::String(as_string());}
315+
Py::Object repr() { return Py::String(as_string());}
316+
std::string as_string() {
317+
if (_type==IDENTITY) return "Identity";
318+
else if (_type==LOG10) return "Log10";
319+
else throw Py::ValueError("Unrecognized function type");
320+
}
321+
322+
Py::Object set_type(const Py::Tuple &args) {
323+
args.verify_length(1);
324+
_type = Py::Int(args[0]);
325+
return Py::Object();
326+
}
327+
328+
Py::Object get_type(const Py::Tuple &args) {
329+
return Py::Int((int)_type);
330+
}
314331

315332
// the python forward and inverse functions
316333
Py::Object map(const Py::Tuple &args);
317334
Py::Object inverse(const Py::Tuple &args);
318335

319336
// the api forward and inverse functions
320-
virtual double operator()(const double& )=0;
321-
virtual double inverse_api(const double& )=0;
322-
323-
};
324-
325-
class Identity : public Func {
326-
public:
327-
328-
static void init_type(void);
329-
330-
// the api forward and inverse functions
331-
double operator()(const double& x) {return x;}
332-
double inverse_api(const double& x) {return x;}
333-
};
334-
335-
class Log : public Func {
336-
public:
337-
338-
static void init_type(void);
339-
340-
double operator()(const double& x) {
341-
if (x<=0) {
342-
throw Py::ValueError("Cannot take log of nonpositive value");
343-
337+
double operator()(const double& x) {
338+
if (_type==IDENTITY) return x;
339+
else if (_type==LOG10) {
340+
if (x<=0) {
341+
throw Py::ValueError("Cannot take log of nonpositive value");
342+
343+
}
344+
return log10(x);
344345
}
345-
return log10(x);
346-
};
346+
else
347+
throw Py::ValueError("Unrecognized function type");
348+
}
349+
double inverse_api(const double& x) {
350+
if (_type==IDENTITY) return x;
351+
else if (_type==LOG10) return pow(10.0, x);
352+
else throw Py::ValueError("Unrecognized function type");
347353

348-
//the inverse mapping
349-
double inverse_api(const double& x) {
350-
return pow(10.0, x);
351-
};
354+
}
355+
356+
enum {IDENTITY, LOG10};
357+
private:
358+
unsigned int _type;
352359
};
353360

354361
class FuncXY : public Py::PythonExtension<FuncXY> {
@@ -570,8 +577,6 @@ class _transforms_module : public Py::ExtensionModule<_transforms_module>
570577

571578

572579
Func::init_type();
573-
Identity::init_type();
574-
Log::init_type();
575580

576581
FuncXY::init_type();
577582
PolarXY::init_type();
@@ -589,11 +594,8 @@ class _transforms_module : public Py::ExtensionModule<_transforms_module>
589594
"Bbox(ll, ur)");
590595
add_varargs_method("Interval", &_transforms_module::new_interval,
591596
"Interval(val1, val2)");
592-
593-
add_varargs_method("Identity", &_transforms_module::new_identity,
594-
"Identity())");
595-
add_varargs_method("Log", &_transforms_module::new_log,
596-
"Log())");
597+
add_varargs_method("Func", &_transforms_module::new_func,
598+
"Func(typecode)");
597599

598600
add_varargs_method("FuncXY", &_transforms_module::new_funcxy,
599601
"FuncXY(funcx, funcy)");
@@ -619,8 +621,8 @@ class _transforms_module : public Py::ExtensionModule<_transforms_module>
619621
Py::Object new_interval (const Py::Tuple &args);
620622
Py::Object new_affine (const Py::Tuple &args);
621623

622-
Py::Object new_identity (const Py::Tuple &args);
623-
Py::Object new_log (const Py::Tuple &args);
624+
Py::Object new_func (const Py::Tuple &args);
625+
624626

625627
Py::Object new_funcxy (const Py::Tuple &args);
626628
Py::Object new_polarxy (const Py::Tuple &args);

unit/transforms_unit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from matplotlib.numerix import array, rand, asarray, alltrue, rand
44
from matplotlib.transforms import Point, Bbox, Value, Affine
55
from matplotlib.transforms import multiply_affines
6-
from matplotlib.transforms import Identity, Log, FuncXY, PolarXY
6+
from matplotlib.transforms import Func, IDENTITY, LOG10, FuncXY, PolarXY
77
from matplotlib.transforms import SeparableTransformation
88
from matplotlib.transforms import identity_transform, unit_bbox, identity_funcxy
99
from matplotlib.transforms import get_bbox_transform
@@ -168,7 +168,7 @@ def rand_transform():
168168

169169

170170
transform = rand_transform()
171-
transform.set_funcx(Log())
171+
transform.set_funcx(Func(LOG10))
172172

173173
x = rand(100)
174174
y = rand(100)

0 commit comments

Comments
 (0)