Skip to content

Commit

Permalink
fixed several log tick and scaling issues
Browse files Browse the repository at this point in the history
svn path=/trunk/matplotlib/; revision=333
  • Loading branch information
jdh2358 committed Jun 7, 2004
1 parent 144cb60 commit 179ca0c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 65 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
New entries should be added at the top

2004-06-07 Fixed several problems with log ticks and scaling - JDH

2004-06-07 Fixed width/height issues for images - JDH

2004-06-03 Fixed draw_if_interactive bug for semilogx;
Expand Down
37 changes: 14 additions & 23 deletions src/_transforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ Func::inverse(const Py::Tuple &args) {

double xout = this->inverse_api(xin);
return Py::Float(xout);

};

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

}



Py::Object _transforms_module::new_identity (const Py::Tuple &args)
{
args.verify_length(0);
return Py::Object( new Identity() );
}

Py::Object _transforms_module::new_log (const Py::Tuple &args)
Py::Object _transforms_module::new_func (const Py::Tuple &args)
{
args.verify_length(0);
return Py::Object( new Log() );

args.verify_length(1);
int typecode = Py::Int(args[0]);
return Py::Object(new Func(typecode));
}

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


Py::Object _transforms_module::new_polarxy (const Py::Tuple &args)
{
args.verify_length(0);
Expand Down Expand Up @@ -1113,22 +1108,13 @@ void Func::init_type()
{
behaviors().name("Func");
behaviors().doc("Map double -> double");
behaviors().supportRepr();
add_varargs_method("map", &Func::map, "map(x)\n");
add_varargs_method("inverse", &Func::inverse, "inverse(y)\n");
add_varargs_method("set_type", &Func::set_type, "set_type(TYPE)\n");
add_varargs_method("get_type", &Func::get_type, "get_type()\n");
}

void Identity::init_type()
{
behaviors().name("Identity");
behaviors().doc("Map x-> x");
}

void Log::init_type()
{
behaviors().name("Log");
behaviors().doc("Map x-> log10(x)");
}

void FuncXY::init_type()
{
behaviors().name("FuncXY");
Expand Down Expand Up @@ -1209,6 +1195,11 @@ DL_EXPORT(void)
_transforms = new _transforms_module;

import_array();


Py::Dict d = _transforms->moduleDictionary();
d["LOG10"] = Py::Int((int)Func::LOG10);
d["IDENTITY"] = Py::Int((int)Func::IDENTITY);
};


Expand Down
82 changes: 42 additions & 40 deletions src/_transforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,47 +308,54 @@ class Bbox: public Py::PythonExtension<Bbox> {
//double. Also can serve as a lazy value evaluator
class Func : public Py::PythonExtension<Func> {
public:

Func( unsigned int type=IDENTITY ) : _type(type) {};
static void init_type(void);

Py::Object str() { return Py::String(as_string());}
Py::Object repr() { return Py::String(as_string());}
std::string as_string() {
if (_type==IDENTITY) return "Identity";
else if (_type==LOG10) return "Log10";
else throw Py::ValueError("Unrecognized function type");
}

Py::Object set_type(const Py::Tuple &args) {
args.verify_length(1);
_type = Py::Int(args[0]);
return Py::Object();
}

Py::Object get_type(const Py::Tuple &args) {
return Py::Int((int)_type);
}

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

// the api forward and inverse functions
virtual double operator()(const double& )=0;
virtual double inverse_api(const double& )=0;

};

class Identity : public Func {
public:

static void init_type(void);

// the api forward and inverse functions
double operator()(const double& x) {return x;}
double inverse_api(const double& x) {return x;}
};

class Log : public Func {
public:

static void init_type(void);

double operator()(const double& x) {
if (x<=0) {
throw Py::ValueError("Cannot take log of nonpositive value");

double operator()(const double& x) {
if (_type==IDENTITY) return x;
else if (_type==LOG10) {
if (x<=0) {
throw Py::ValueError("Cannot take log of nonpositive value");

}
return log10(x);
}
return log10(x);
};
else
throw Py::ValueError("Unrecognized function type");
}
double inverse_api(const double& x) {
if (_type==IDENTITY) return x;
else if (_type==LOG10) return pow(10.0, x);
else throw Py::ValueError("Unrecognized function type");

//the inverse mapping
double inverse_api(const double& x) {
return pow(10.0, x);
};
}

enum {IDENTITY, LOG10};
private:
unsigned int _type;
};

class FuncXY : public Py::PythonExtension<FuncXY> {
Expand Down Expand Up @@ -570,8 +577,6 @@ class _transforms_module : public Py::ExtensionModule<_transforms_module>


Func::init_type();
Identity::init_type();
Log::init_type();

FuncXY::init_type();
PolarXY::init_type();
Expand All @@ -589,11 +594,8 @@ class _transforms_module : public Py::ExtensionModule<_transforms_module>
"Bbox(ll, ur)");
add_varargs_method("Interval", &_transforms_module::new_interval,
"Interval(val1, val2)");

add_varargs_method("Identity", &_transforms_module::new_identity,
"Identity())");
add_varargs_method("Log", &_transforms_module::new_log,
"Log())");
add_varargs_method("Func", &_transforms_module::new_func,
"Func(typecode)");

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

Py::Object new_identity (const Py::Tuple &args);
Py::Object new_log (const Py::Tuple &args);
Py::Object new_func (const Py::Tuple &args);


Py::Object new_funcxy (const Py::Tuple &args);
Py::Object new_polarxy (const Py::Tuple &args);
Expand Down
4 changes: 2 additions & 2 deletions unit/transforms_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from matplotlib.numerix import array, rand, asarray, alltrue, rand
from matplotlib.transforms import Point, Bbox, Value, Affine
from matplotlib.transforms import multiply_affines
from matplotlib.transforms import Identity, Log, FuncXY, PolarXY
from matplotlib.transforms import Func, IDENTITY, LOG10, FuncXY, PolarXY
from matplotlib.transforms import SeparableTransformation
from matplotlib.transforms import identity_transform, unit_bbox, identity_funcxy
from matplotlib.transforms import get_bbox_transform
Expand Down Expand Up @@ -168,7 +168,7 @@ def rand_transform():


transform = rand_transform()
transform.set_funcx(Log())
transform.set_funcx(Func(LOG10))

x = rand(100)
y = rand(100)
Expand Down

0 comments on commit 179ca0c

Please sign in to comment.