MacOSX backend incorrectly displays plot/scatter under Affine2D transform #1886

Closed
jdgleeson opened this Issue Apr 6, 2013 · 8 comments

Comments

Projects
None yet
5 participants
@jdgleeson

The default MacOSX backend does not display the expected output for the following code. Both the QT4Agg and TkAgg backends display correctly.

Code illustrating the problem:

# from matplotlib import use
# use("QT4Agg")
# use("TkAgg")
import matplotlib.pyplot as plt
import matplotlib.transforms as mtrans
import numpy as np

plt.figure()
ax = plt.subplot(111)
base_trans = ax.transData
mtx = np.array([[1,1,0], 
                [0,1,0], 
                [0,0,1]])
tr = mtrans.Affine2D(matrix=mtx) + base_trans

plt.plot([1,2,3], [1,2,3], 'gray', transform=tr)
plt.scatter([1,2,3], [1,2,3], c='k', marker='D', transform=tr)
plt.show()

Environment:

>>> import matplotlib
>>> matplotlib.__version__
'1.2.0'
>>> matplotlib.__file__
'/opt47/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/__init__.pyc'
>>> matplotlib.get_configdir()
'/Users/jdgleeson/.matplotlib'
>>> matplotlib.get_backend()
'MacOSX'

TkAgg.png showing expected results (via X11 on my Mac).

TkAgg

MacOSX.png shows incorrect results.

MacOSX

@goldnd

This comment has been minimized.

Show comment Hide comment
@goldnd

goldnd Apr 6, 2013

The same thing happens with quiver plots.

goldnd commented Apr 6, 2013

The same thing happens with quiver plots.

@pelson

This comment has been minimized.

Show comment Hide comment
@pelson

pelson Apr 7, 2013

Member

Thanks for reporting @jdgleeson (and the comment @goldnd).

Member

pelson commented Apr 7, 2013

Thanks for reporting @jdgleeson (and the comment @goldnd).

@mdboom

This comment has been minimized.

Show comment Hide comment
@mdboom

mdboom Apr 8, 2013

Owner

@mdehoon: Any thoughts?

Owner

mdboom commented Apr 8, 2013

@mdehoon: Any thoughts?

@mdehoon

This comment has been minimized.

Show comment Hide comment
@mdehoon

mdehoon Apr 9, 2013

Contributor

It looks like b and c in the function _transformation_converter in src/_macosx.m should be switched.
@jdgleeson @goldnd , could you try this and do some tests?

Contributor

mdehoon commented Apr 9, 2013

It looks like b and c in the function _transformation_converter in src/_macosx.m should be switched.
@jdgleeson @goldnd , could you try this and do some tests?

@jdgleeson

This comment has been minimized.

Show comment Hide comment
@jdgleeson

jdgleeson Apr 9, 2013

On 2013-04-09, at 2:03 AM, mdehoon wrote:

It looks like b and c in the function _transformation_converter in
src/_macosx.m should be switched.
@jdgleeson @goldnd , could you try this and do some tests?

That fixed it for me! Thanks.

--- src/_macosx.m.orig 2012-11-08 09:38:38.000000000 -0700
+++ src/_macosx.m 2013-04-09 09:17:37.000000000 -0600
@@ -1205,8 +1205,8 @@
return 0;
}
const double a = (double)PyArray_GETPTR2(object, 0, 0);

  • const double b = (double)PyArray_GETPTR2(object, 0, 1);
  • const double c = (double)PyArray_GETPTR2(object, 1, 0);
  • const double c = (double)PyArray_GETPTR2(object, 0, 1);
  • const double b = (double)PyArray_GETPTR2(object, 1, 0);
    const double d = (double)PyArray_GETPTR2(object, 1, 1);
    const double tx = (double)PyArray_GETPTR2(object, 0, 2);
    const double ty = (double)PyArray_GETPTR2(object, 1, 2);

On 2013-04-09, at 2:03 AM, mdehoon wrote:

It looks like b and c in the function _transformation_converter in
src/_macosx.m should be switched.
@jdgleeson @goldnd , could you try this and do some tests?

That fixed it for me! Thanks.

--- src/_macosx.m.orig 2012-11-08 09:38:38.000000000 -0700
+++ src/_macosx.m 2013-04-09 09:17:37.000000000 -0600
@@ -1205,8 +1205,8 @@
return 0;
}
const double a = (double)PyArray_GETPTR2(object, 0, 0);

  • const double b = (double)PyArray_GETPTR2(object, 0, 1);
  • const double c = (double)PyArray_GETPTR2(object, 1, 0);
  • const double c = (double)PyArray_GETPTR2(object, 0, 1);
  • const double b = (double)PyArray_GETPTR2(object, 1, 0);
    const double d = (double)PyArray_GETPTR2(object, 1, 1);
    const double tx = (double)PyArray_GETPTR2(object, 0, 2);
    const double ty = (double)PyArray_GETPTR2(object, 1, 2);
@mdehoon

This comment has been minimized.

Show comment Hide comment
@mdehoon

mdehoon Apr 10, 2013

Contributor

@jdgleeson Thanks for trying this fix. Could you also try the other matplotlib examples to make sure this doesn't introduce some new bug?

Contributor

mdehoon commented Apr 10, 2013

@jdgleeson Thanks for trying this fix. Could you also try the other matplotlib examples to make sure this doesn't introduce some new bug?

@jdgleeson

This comment has been minimized.

Show comment Hide comment
@jdgleeson

jdgleeson Apr 10, 2013

On 2013-04-09, at 6:41 PM, mdehoon wrote:

@jdgleeson Thanks for trying this fix. Could you also try the other
matplotlib examples to make sure this doesn't introduce some new bug?

Ran 1214 tests in 973.796s

FAILED (KNOWNFAIL=300, SKIP=3, failures=2)

Sorry for the delay; I was trying to install Inkscape and ran into a
problem building a dependency.

The two failures are in

FAIL: matplotlib.tests.test_text.test_font_styles.test

ImageComparisonFailure: images not close: /Users/jdgleeson/
result_images/test_text/font_styles.png vs. /Users/jdgleeson/
result_images/test_text/font_styles-expected.png (RMS 47.353)

ImageComparisonFailure: images not close: /Users/jdgleeson/
result_images/test_text/font_styles_pdf.png vs. /Users/jdgleeson/
result_images/test_text/font_styles-expected_pdf.png (RMS 23.423)

In both cases, all fonts look the same as "Normal Font"

I found this issue which may explain it.
macosx backend doesn't find fonts the same way as other backends
#781

On 2013-04-09, at 6:41 PM, mdehoon wrote:

@jdgleeson Thanks for trying this fix. Could you also try the other
matplotlib examples to make sure this doesn't introduce some new bug?

Ran 1214 tests in 973.796s

FAILED (KNOWNFAIL=300, SKIP=3, failures=2)

Sorry for the delay; I was trying to install Inkscape and ran into a
problem building a dependency.

The two failures are in

FAIL: matplotlib.tests.test_text.test_font_styles.test

ImageComparisonFailure: images not close: /Users/jdgleeson/
result_images/test_text/font_styles.png vs. /Users/jdgleeson/
result_images/test_text/font_styles-expected.png (RMS 47.353)

ImageComparisonFailure: images not close: /Users/jdgleeson/
result_images/test_text/font_styles_pdf.png vs. /Users/jdgleeson/
result_images/test_text/font_styles-expected_pdf.png (RMS 23.423)

In both cases, all fonts look the same as "Normal Font"

I found this issue which may explain it.
macosx backend doesn't find fonts the same way as other backends
#781

@mdehoon

This comment has been minimized.

Show comment Hide comment
@mdehoon

mdehoon Apr 11, 2013

Contributor

@jdgleeson Thanks! Then at least we know that this fix doesn't introduce new problems, as
the two test failures are not related to the current issue.

Contributor

mdehoon commented Apr 11, 2013

@jdgleeson Thanks! Then at least we know that this fix doesn't introduce new problems, as
the two test failures are not related to the current issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment