Skip to content

Fix incorrect text line spacing. #8495

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 5 commits into from
Apr 17, 2017
Merged

Conversation

Keerush
Copy link
Contributor

@Keerush Keerush commented Apr 15, 2017

Added line spacing property to get_prop_tup() in text.py, so that the intended line spacing is applied to text. Added tests to check line spacing of text in plots are corrected rendered.
Fixes issue #7523.

@@ -421,3 +421,34 @@ def test_font_scaling():

for i, fs in enumerate(range(4, 43, 2)):
ax.text(0.1, i*30, "{fs} pt font size".format(fs=fs), fontsize=fs)


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

Choose a reason for hiding this comment

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

You should parametrize this one test (it might have to wait for #8380, though.)

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)
plt.show()
Copy link
Member

Choose a reason for hiding this comment

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

Not necessary.


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)
Copy link
Member

Choose a reason for hiding this comment

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

It'd be preferable to use object-oriented API, I think.

@@ -421,3 +421,11 @@ def test_font_scaling():

for i, fs in enumerate(range(4, 43, 2)):
ax.text(0.1, i*30, "{fs} pt font size".format(fs=fs), fontsize=fs)


@pytest.mark.parametrize('spacing1, spacing2', [(2, 0.4), (0.4, 2)])
Copy link
Member

Choose a reason for hiding this comment

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

I am very confused by what this is doing and how this relates to the added image.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The bug with the text line spacing was that adding multiple text with different line spacing would not be correctly rendered. So this test would check that the intended line spacing for each the texts was applied. The second set of parameters was to check that calling text() in a different order would still produce the same result.

@tacaswell
Copy link
Member

I am not sure that the image comparison plays niecly with paraterization (yet) https://codecov.io/gh/matplotlib/matplotlib/compare/1c0b96c592e2668f402cee131baeef9d1c2754bb...04ed906ab643afbc12028ab5bf846a6750dd28fe/diff looks like the body of the test is not being run.

If you want to test the order like this in is probably better to put all 4 strtings on the same axes.

@QuLogic
Copy link
Member

QuLogic commented Apr 16, 2017

Yes, would need #8380 probably. Is an image test strictly required? Could it check that the extent is different for the two test boxes?

@Keerush
Copy link
Contributor Author

Keerush commented Apr 16, 2017

Using image test was just something I was familiar with, but I can update the tests to look at the extent instead.

@tacaswell
Copy link
Member

I also just merged #8380 so the paramterization should work now 😄.

If you go the checking the exetents route, make sure to rebase the image out of the history and to make sure to force a draw (fig.canvas.draw() ) before checking the extents.

@tacaswell
Copy link
Member

@Keerush Are you comfortable doing a rebase? If so, see http://matplotlib.org/devel/gitwash/development_workflow.html?highlight=rebase#rebasing-a-pull-request-pr but you will want to do git rebase -i matplotlib/master and follow the directions (best to squash everything in this case.

If not, I can take care of it.

@tacaswell tacaswell modified the milestones: 2.0.1 (next bug fix release), 2.1 (next point release) Apr 17, 2017
@Keerush
Copy link
Contributor Author

Keerush commented Apr 17, 2017

@tacaswell I haven't done a rebase before. I think it would be better if you did it.

@tacaswell tacaswell merged commit d930503 into matplotlib:master Apr 17, 2017
@tacaswell
Copy link
Member

tacaswell commented Apr 17, 2017

@Keerush You will need to do some fix up your master branch. The easiest way to do this is to simply delete your fork and local checkout, re-fork and re-clone.

The other option is to do

git checkout master
git remote matplotlib
git reset --hard matplotlib/master
git push --force origin master

Assuming that the remote name of your fork is 'origin' and the upstream repository is 'matplotlib'

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

Successfully merging this pull request may close these issues.

4 participants