Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Allow SVG Text-as-Text to Use Data Coordinates #14114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 4, 2019

Conversation

njwhite
Copy link
Contributor

@njwhite njwhite commented May 1, 2019

PR Summary

Drawing SVG text as text (svg.fonttype is "none") should allow locations in data-coordinates. The included test case fails on master as the x-value (a np.datetime64) is expected to be a float (see stacktrace before fix below).

____________________________________________________ test_svgnone_with_data_coordinates ____________________________________________________

    def test_svgnone_with_data_coordinates():
        plt.rcParams['svg.fonttype'] = 'none'
        expected = 'TEXT'
    
        fig, ax = plt.subplots()
        ax.text(np.datetime64('2019-06-30'), 1, expected)
        ax.set_xlim(np.datetime64('2019-01-01'), np.datetime64('2019-12-31'))
        ax.set_ylim(0, 2)
    
        fd = BytesIO()
>       fig.savefig(fd, format='svg')

lib/matplotlib/tests/test_backend_svg.py:211: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
lib/matplotlib/figure.py:2186: in savefig
    self.canvas.print_figure(fname, **kwargs)
lib/matplotlib/backend_bases.py:2079: in print_figure
    **kwargs)
lib/matplotlib/backends/backend_svg.py:1199: in print_svg
    result = self._print_svg(filename, fh, **kwargs)
lib/matplotlib/backends/backend_svg.py:1224: in _print_svg
    self.figure.draw(renderer)
lib/matplotlib/artist.py:38: in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
lib/matplotlib/figure.py:1716: in draw
    renderer, self, artists, self.suppressComposite)
lib/matplotlib/image.py:135: in _draw_list_compositing_images
    a.draw(renderer)
lib/matplotlib/artist.py:38: in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
lib/matplotlib/axes/_base.py:2630: in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
lib/matplotlib/image.py:135: in _draw_list_compositing_images
    a.draw(renderer)
lib/matplotlib/artist.py:38: in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
lib/matplotlib/text.py:718: in draw
    ismath=ismath, mtext=mtext)
lib/matplotlib/backends/backend_svg.py:1159: in draw_text
    self._draw_text_as_text(gc, x, y, s, prop, angle, ismath, mtext)
lib/matplotlib/backends/backend_svg.py:1043: in _draw_text_as_text
    ax, ay = transform.transform_point(mtext.get_position())
lib/matplotlib/transforms.py:1468: in transform_point
    return self.transform(np.asarray([point]))[0]
lib/matplotlib/transforms.py:1381: in transform
    res = self.transform_affine(self.transform_non_affine(values))
lib/matplotlib/transforms.py:2348: in transform_affine
    return self.get_affine().transform(points)
lib/matplotlib/transforms.py:1679: in transform
    return self.transform_affine(values)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <matplotlib.transforms.Affine2D object at 0x7f76ef2b02e8>, points = array([[numpy.datetime64('2019-06-30'), 1]], dtype=object)

    def transform_affine(self, points):
        mtx = self.get_matrix()
        if isinstance(points, np.ma.MaskedArray):
            tpoints = affine_transform(points.data, mtx)
            return np.ma.MaskedArray(tpoints, mask=np.ma.getmask(points))
>       return affine_transform(points, mtx)
E       TypeError: Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe'

lib/matplotlib/transforms.py:1761: TypeError

lib/matplotlib/tests/test_backend_svg.py Outdated Show resolved Hide resolved
@timhoffm
Copy link
Member

timhoffm commented May 2, 2019

flake8 complains:

./lib/matplotlib/backends/backend_svg.py:1043:80: E501 line too long (81 > 79 characters)
1 E501 line too long (81 > 79 characters)

Please fix this.

@njwhite
Copy link
Contributor Author

njwhite commented May 2, 2019

Thanks for the reviews @anntzer @timhoffm - I've fixed all the issues you've highlighted.

Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks for the PR!

@timhoffm timhoffm merged commit 79ccf53 into matplotlib:master May 4, 2019
@timhoffm
Copy link
Member

timhoffm commented May 4, 2019

Thanks! And congratulations to your first contribution to Matplotllib. Maybe see you back some time.

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

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.