Skip to content

Multi-line text instances differing in linespacing not rendered correctly #7523

Closed

Description

@ondrejdee
  • matplotlib 1.5.3 (pip install)
  • python 2.7.6 (apt-get from ubuntu repository)
  • ubuntu 14.04
  • goal: display 2-line texts which differ by linespacing.
  • issue: when the text instances have the same parameters (coordinates, text string, alpha) except for the linespacing, the second one is displayed over the first one. The linespacing of the first instance is used for the second instance as well.
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt

def two_2line_texts(x1, y1, spacing1, x2, y2, spacing2): 

    text_string = 'line1\nline2'
    plt.text(x1, y1, text_string, linespacing = spacing1, alpha = 0.5)
    plt.text(x2, y2, text_string, linespacing = spacing2, alpha = 0.5)

# fig 1: 
two_2line_texts(x1 = .5, y1 = .5, spacing1 = 2, 
                x2 = .5, y2 = .5, spacing2 = 0.4) 

# fig 2: 
two_2line_texts(x1 = .5, y1 = .5, spacing1 = 0.4, 
                x2 = .5, y2 = .5, spacing2 = 2) 

# fig 3: 
two_2line_texts(x1 = .5, y1 = .5000000001, spacing1 = 0.4, 
                x2 = .5, y2 = .5, spacing2 = 2) 

fig 1:
linespacing_pars1

fig 2:
linespacing_pars2

fig 3:
linespacing_pars3

Activity

  1. added this to the milestone on Nov 29, 2016
  2. QuLogic commented on Nov 29, 2016

    @QuLogic
    Member

    This is a really easy fix; one needs to add self._linespacing to matplotlib.text.Text.get_prop_tup, but it needs tests, etc., which I don't have time for at the moment, so tagging new-contributor-friendly.

  3. vincentpham1991 commented on Dec 7, 2016

    @vincentpham1991

    Can I take a crack at this? I would like to contribute to matplotlib.

  4. QuLogic commented on Dec 7, 2016

    @QuLogic
    Member

    Sure, no need to ask, just follow the changes that I outlined and open a PR.

  5. vincentpham1991 commented on Dec 8, 2016

    @vincentpham1991

    I am trying to try out how to test functions in matplotlib. I ran the sample test on the documentation:
    python tests.py "matplotlib.tests.test_simplification:test_clipping"

    but got the following error:

    Python byte-compilation optimization level: 0
    Traceback (most recent call last):
        File "tests.py", line 46, in <module>
            success = test(argv=sys.argv[0:1] + extra_args, switch_backend_warn=False)
    TypeError: test() got an unexpected keyword argument 'argv'
    

    I am not sure how to proceed if I can't test my changes.

  6. phobson commented on Dec 8, 2016

    @phobson
    Member

    @vincentpham1991 what OS/platform are you on?

  7. vincentpham1991 commented on Dec 8, 2016

    @vincentpham1991

    I am using Mac OS 10.11.6

  8. phobson commented on Dec 8, 2016

    @phobson
    Member

    can you describe your setup a little further?
    (e.g., how up-to-date is your source branch? are you using virtual or conda environments? which version of python? how did you install your development version of matplotlib?)

  9. vincentpham1991 commented on Dec 8, 2016

    @vincentpham1991

    I solved the issue I mentioned above but am running into another issue:
    Whenever I run the test, I get the following error, causing tests that compares against images to fail:

    UserWarning: matplotlib is not built with the correct FreeType version to run tests.  Set      
    local_freetype=True in setup.cfg and rebuild. Expect many image comparison failures below.
    Expected freetype version 2.7.0. Found freetype version 2.6.1. Freetype build type is not local
    

    I pulled from the master branch from github a couple of hours ago, so it should be the latest version. I just pulled again to confirm.

    From the package, I ran python setup.py develop.

    I am using the base version of python installed by brew. My current version is Python 2.7.10.

    I renamed setup.cfg.template to setup.cfg and uncommented:

    local_freetype=True
    

    As well as:

    tests = True
    sample_data = True
    toolkits = True
    
  10. QuLogic commented on Dec 8, 2016

    @QuLogic
    Member

    Make sure to change setup.cfg before running python setup.py develop (though I prefer pip install -e .).

  11. vincentpham1991 commented on Dec 8, 2016

    @vincentpham1991

    Yes, I made the change to setup.cfg before running the setup.

  12. tacaswell commented on Dec 8, 2016

    @tacaswell
    Member

    If you installed, changed the config, and then installed again, it may still be re-using the objects built and linked from the first install. The python builder is smart, but not that smart.

    See http://matplotlib.org/devdocs/devel/contributing.html#retrieving-and-installing-the-latest-version-of-the-code

  13. added a commit that references this issue on Mar 1, 2017
  14. added a commit that references this issue on Apr 15, 2017
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

    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions