Skip to content

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

Closed

Description

@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

Activity

  1. goldnd commented on Apr 6, 2013

    @goldnd

    The same thing happens with quiver plots.

  2. pelson commented on Apr 7, 2013

    @pelson
    Member

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

  3. mdboom commented on Apr 8, 2013

    @mdboom
    Member

    @mdehoon: Any thoughts?

  4. mdehoon commented on Apr 9, 2013

    @mdehoon
    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?

  5. jdgleeson commented on Apr 9, 2013

    @jdgleeson
    Author

    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);
  6. mdehoon commented on Apr 10, 2013

    @mdehoon
    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?

  7. jdgleeson commented on Apr 10, 2013

    @jdgleeson
    Author

    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

  8. mdehoon commented on Apr 11, 2013

    @mdehoon
    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.

  9. added a commit that references this issue on Apr 17, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions