Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/pyplots/annotate_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
ax.set_ylim(-1, 1)

xdata, ydata = 5, 0
xdisplay, ydisplay = ax.transData.transform((xdata, ydata))
xdisplay, ydisplay = ax.transData.transform_point((xdata, ydata))

bbox = dict(boxstyle="round", fc="0.8")
arrowprops = dict(
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
if elt[0] == 'font':
self.file.output(elt[1], elt[2], Op.selectfont)
elif elt[0] == 'text':
curx, cury = mytrans.transform((elt[1], elt[2]))
curx, cury = mytrans.transform_point((elt[1], elt[2]))
self._setup_textpos(curx, cury, angle, oldx, oldy)
oldx, oldy = curx, cury
if len(elt[3]) == 1:
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/sankey.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ def _get_angle(a, r):
if prior is None:
if rotation != 0: # By default, none of this is needed.
angles = [_get_angle(angle, rotation) for angle in angles]
rotate = Affine2D().rotate_deg(rotation * 90).transform_point
rotate = Affine2D().rotate_deg(rotation * 90).transform_affine
tips = rotate(tips)
label_locations = rotate(label_locations)
vertices = rotate(vertices)
Expand All @@ -737,10 +737,10 @@ def _get_angle(a, r):
rotation = (self.diagrams[prior].angles[connect[0]] -
angles[connect[1]])
angles = [_get_angle(angle, rotation) for angle in angles]
rotate = Affine2D().rotate_deg(rotation * 90).transform_point
rotate = Affine2D().rotate_deg(rotation * 90).transform_affine
tips = rotate(tips)
offset = self.diagrams[prior].tips[connect[0]] - tips[connect[1]]
translate = Affine2D().translate(*offset).transform_point
translate = Affine2D().translate(*offset).transform_affine
tips = translate(tips)
label_locations = translate(rotate(label_locations))
vertices = translate(rotate(vertices))
Expand Down
136 changes: 58 additions & 78 deletions src/py_converters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,47 @@

extern "C" {

static int convert_string_enum(PyObject *obj, const char *name, const char **names, int *values, int *result)
{
PyObject *bytesobj;
char *str;

if (obj == NULL || obj == Py_None) {
return 1;
}

if (PyUnicode_Check(obj)) {
bytesobj = PyUnicode_AsASCIIString(obj);
if (bytesobj == NULL) {
return 0;
}
} else if (PyBytes_Check(obj)) {
Py_INCREF(obj);
bytesobj = obj;
} else {
PyErr_Format(PyExc_TypeError, "%s must be bytes or unicode", name);
return 0;
}

str = PyBytes_AsString(bytesobj);
if (str == NULL) {
Py_DECREF(bytesobj);
return 0;
}

for ( ; *names != NULL; names++, values++) {
if (strncmp(str, *names, 64) == 0) {
*result = *values;
Py_DECREF(bytesobj);
return 1;
}
}

PyErr_Format(PyExc_ValueError, "invalid %s value", name);
Py_DECREF(bytesobj);
return 0;
}

int convert_from_method(PyObject *obj, const char *name, converter func, void *p)
{
PyObject *value;
Expand Down Expand Up @@ -76,76 +117,29 @@ int convert_bool(PyObject *obj, void *p)

int convert_cap(PyObject *capobj, void *capp)
{
PyObject *capstrobj;
char *capstr;
agg::line_cap_e *cap = (agg::line_cap_e *)capp;

if (capobj == NULL || capobj == Py_None) {
return 1;
}

capstrobj = PyUnicode_AsASCIIString(capobj);
if (capstrobj == NULL) {
return 0;
}
const char *names[] = {"butt", "round", "projecting", NULL};
int values[] = {agg::butt_cap, agg::round_cap, agg::square_cap};
int result;

capstr = PyBytes_AsString(capstrobj);
if (capstr == NULL) {
Py_DECREF(capstrobj);
if (!convert_string_enum(capobj, "capstyle", names, values, &result)) {
return 0;
}

if (strncmp(capstr, "butt", 5) == 0) {
*cap = agg::butt_cap;
} else if (strncmp(capstr, "round", 6) == 0) {
*cap = agg::round_cap;
} else if (strncmp(capstr, "projecting", 11) == 0) {
*cap = agg::square_cap;
} else {
PyErr_Format(PyExc_ValueError, "Unknown capstyle '%s'", capstr);
Py_DECREF(capstrobj);
return 0;
}

Py_DECREF(capstrobj);

*(agg::line_cap_e *)capp = (agg::line_cap_e)result;
return 1;
}

int convert_join(PyObject *joinobj, void *joinp)
{
PyObject *joinstrobj;
char *joinstr;
agg::line_join_e *join = (agg::line_join_e *)joinp;

if (joinobj == NULL || joinobj == Py_None) {
return 1;
}

joinstrobj = PyUnicode_AsASCIIString(joinobj);
if (joinstrobj == NULL) {
return 0;
}
const char *names[] = {"miter", "round", "bevel", NULL};
int values[] = {agg::miter_join_revert, agg::round_join, agg::bevel_join};
int result;

joinstr = PyBytes_AsString(joinstrobj);
if (joinstr == NULL) {
Py_DECREF(joinstrobj);
if (!convert_string_enum(joinobj, "joinstyle", names, values, &result)) {
return 0;
}

if (strncmp(joinstr, "miter", 6) == 0) {
*join = agg::miter_join_revert;
} else if (strncmp(joinstr, "round", 6) == 0) {
*join = agg::round_join;
} else if (strncmp(joinstr, "bevel", 6) == 0) {
*join = agg::bevel_join;
} else {
PyErr_Format(PyExc_ValueError, "Unknown joinstyle '%s'", joinstr);
Py_DECREF(joinstrobj);
return 0;
}

Py_DECREF(joinstrobj);
*(agg::line_join_e *)joinp = (agg::line_join_e)result;
return 1;
}

Expand Down Expand Up @@ -497,32 +491,18 @@ int convert_gcagg(PyObject *pygc, void *gcp)
int convert_offset_position(PyObject *obj, void *offsetp)
{
e_offset_position *offset = (e_offset_position *)offsetp;
PyObject *offsetstrobj;
char *offsetstr;
const char *names[] = {"data", NULL};
int values[] = {OFFSET_POSITION_DATA};
int result;

*offset = OFFSET_POSITION_FIGURE;

if (obj == NULL || obj == Py_None) {
return 1;
}

offsetstrobj = PyUnicode_AsASCIIString(obj);
if (offsetstrobj == NULL) {
return 0;
}

offsetstr = PyBytes_AsString(offsetstrobj);
if (offsetstr == NULL) {
Py_DECREF(offsetstrobj);
return 0;
}

if (strncmp(offsetstr, "data", 5) == 0) {
*offset = OFFSET_POSITION_DATA;
if (convert_string_enum(obj, "offset_position", names, values, &result)) {
*offset = (e_offset_position)result;
} else {
PyErr_Clear();
}

Py_DECREF(offsetstrobj);

return 1;
}

Expand Down