Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Legend default style change: smaller, no border #6424

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 4 commits into from
May 28, 2016

Conversation

efiring
Copy link
Member

@efiring efiring commented May 15, 2016

Addresses #5269
This is just a proposal; it changes the default font size from large to small, and removes the boundary. I think that having a smaller font for the legend is a good default, particularly in conjunction with removal of the boundary, because it helps it stand out. Regardless of the boundary, the motivation for the small font is to keep the legend from being too large and obtrusive. I could be convinced to change the font size to medium, but the original default of large made no sense at all.

@efiring efiring added this to the 2.0 (style change major release) milestone May 15, 2016
@efiring
Copy link
Member Author

efiring commented May 15, 2016

The test failure is unrelated. In /Users/efiring/work/programs/py/mpl/tests/result_images/test_axes_grid1/ there has been a change in the size of the test figure that apparently hasn't been propagated.

#legend.loc : best
#legend.isaxes : True
Copy link
Member

Choose a reason for hiding this comment

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

is this not a thing anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. I don't know how long it has been gone, but it is inactive, and marked as such in rcsetup. It would make no sense for it to be an rcParam; it is entirely internal to legend. It is a flag to tell whether it is a figure legend or an axes legend.
Probably the validator for it should emit a warning.

@QuLogic
Copy link
Member

QuLogic commented May 16, 2016

Can you post an example image?

@efiring
Copy link
Member Author

efiring commented May 17, 2016

The first example below is with this PR in effect, and the second is without it.
legend_new
legend0

@efiring
Copy link
Member Author

efiring commented May 17, 2016

Another question about legend defaults: presently scatterpoints is 3 and numpoints is 1. Is there any good reason why scatterpoints should not also be 1?

@tacaswell
Copy link
Member

If the size varies then multiple sized markers are shown in the scatter legend, but there is no scale on it so it is not super helpful.

I am 👍 on making scatter points also default to 1

@ellisonbg
Copy link

I think this change is an improvement. The large font size in the legend is overkill and the legend border isn't needed. Only question, what does this look like when the legend box starts to sit on top of data?

# the relative size of legend markers vs. original
'legend.markerscale': [1.0, validate_float],
'legend.shadow': [False, validate_bool],
# whether or not to draw a frame around legend
'legend.frameon': [True, validate_bool],
'legend.frameon': [False, validate_bool],
Copy link
Member

Choose a reason for hiding this comment

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

maybe leave this true and change legend.edgecolor to 'w' (or 'inherit')?

@kthyng
Copy link
Contributor

kthyng commented May 17, 2016

I definitely prefer having 1 marker in the legend.

@efiring
Copy link
Member Author

efiring commented May 17, 2016

I think the best general result is achieved with something like this:

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 10, 200)

fig, ax = plt.subplots()
ax.plot(x, np.sin(x), label='sine (long label to test big box)')
ax.plot(x, np.cos(x), label='cosine')
ax.plot(x, (x/10)**2, label='quadratic')
ax.plot(x, (x/10)**3, label='cubic')
ax.set_xlabel('This is the x-axis')
ax.set_ylabel('This is the y-axis')
ax.set_title('Example of a proposed default legend')

plt.rcParams['legend.edgecolor'] = 'none'
plt.rcParams['legend.framealpha'] = 0.8
plt.rcParams['legend.frameon'] = True

ax.legend()

fig.savefig('legend_new_long.png')
plt.show()

which yields
legend_new_long
The argument against this is that the PS backend doesn't support alpha. In this case, however, I think that letting that limitation of the archaic PS standard hold us back would be a mistake. The fallback for a PS plot will be no worse than what one would get with a likely alternative: an opaque legend background.

@ellisonbg
Copy link

Nice! I like using alpha for this and wouldn't worry about PS not
supporting it.

On Tue, May 17, 2016 at 12:15 PM, Eric Firing [email protected]
wrote:

I think the best general result is achieved with something like this:

import numpy as npimport matplotlib.pyplot as plt

x = np.linspace(0, 10, 200)

fig, ax = plt.subplots()
ax.plot(x, np.sin(x), label='sine (long label to test big box)')
ax.plot(x, np.cos(x), label='cosine')
ax.plot(x, (x/10)**2, label='quadratic')
ax.plot(x, (x/10)**3, label='cubic')
ax.set_xlabel('This is the x-axis')
ax.set_ylabel('This is the y-axis')
ax.set_title('Example of a proposed default legend')

plt.rcParams['legend.edgecolor'] = 'none'
plt.rcParams['legend.framealpha'] = 0.8
plt.rcParams['legend.frameon'] = True

ax.legend()

fig.savefig('legend_new_long.png')
plt.show()

which yields
[image: legend_new_long]
https://cloud.githubusercontent.com/assets/85125/15335679/17e904ba-1c0f-11e6-9563-f4aab118e65b.png
The argument against this is that the PS backend doesn't support alpha. In
this case, however, I think that letting that limitation of the archaic PS
standard hold us back would be a mistake. The fallback for a PS plot will
be no worse than what one would get with a likely alternative: an opaque
legend background.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#6424 (comment)

Brian E. Granger
Associate Professor of Physics and Data Science
Cal Poly State University, San Luis Obispo
@ellisonbg on Twitter and GitHub
[email protected] and [email protected]

@dopplershift
Copy link
Contributor

Definitely 👍 on the font size change. I'm a little more iffy on dropping the frame, but agree it fits with "less junk by default"; given that, I think the translucent box is a good approach.

@pierre-haessig
Copy link
Contributor

+1 for a smaller legend font. I always end up doing it for publication plots.

Removing the border is fine (alternative I've used often : a light gray border instead of black).

Alpha 0.8 looks great.

@@ -861,7 +861,7 @@ def matplotlib_fname():
_deprecated_ignore_map = {
}

_obsolete_set = set(['tk.pythoninspect', ])
_obsolete_set = set(['tk.pythoninspect', 'legend.isaxes'])
Copy link
Member

Choose a reason for hiding this comment

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

We don't need 2.6 support, right? You could use a set literal here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct.

@u55
Copy link
Contributor

u55 commented May 20, 2016

I actually find it a bit strange looking that the proposed legend fontsize is so much smaller than the tick labels, axis labels, and title. I think I would prefer to change the default legend fontsize to medium rather than small, or alternatively I would prefer to change the default fontsize of all the text objects to one size smaller, with my absolute preference being the latter option.

@efiring
Copy link
Member Author

efiring commented May 20, 2016

Here is the version with medium legend.fontsize instead of small:
legend_medium

@efiring
Copy link
Member Author

efiring commented May 20, 2016

And this is what happens with medium legend and all text reduced by changing font.size from 12 to 10:
legend_medium-10

@u55
Copy link
Contributor

u55 commented May 20, 2016

Yes, I like the 10pt font.

@WeatherGod
Copy link
Member

Actually, I kinda like that last one

On Fri, May 20, 2016 at 2:19 PM, Eric Firing [email protected]
wrote:

And this is what happens with medium legend and all text reduced by
changing font.size from 12 to 10:
[image: legend_medium-10]
https://cloud.githubusercontent.com/assets/85125/15437568/8976b23e-1e63-11e6-9de6-496b8095730f.png


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#6424 (comment)

@efiring
Copy link
Member Author

efiring commented May 20, 2016

Worms swarm out of the can...

Selecting default font size, figure size, and dpi is difficult because so much depends on how the resulting plot will be displayed and used, and on what sort of content it will have. There are questions of proportion, and of absolute size. Will the figure be displayed via projector in a presentation? If so, will it occupy the whole slide, or will it be scaled down? Will it go in a tech report, typically formatted in single-column mode, where space is not at a premium? Or is the target a publication, with text in two columns and every figure shrunken to near-invisibility?
I think the defaults should be slanted towards what works in interactive mode on the screen, in informal documents (tech reports and such), and to some degree in presentations and on the web--since a presentation to one's co-workers, as slides or a web page, is often the next step after one's initial data exploration and analysis. In all these cases we want to have something that works with minimal fiddling; defer most fine-tuning to the final publication stage.
My impression is that for such applications, the present 2.0 default font size of 12 pt is a reasonable choice. It matches typical informal document defaults, and it works in a figure on a slide, even with moderate down-scaling. The advantage of 10 pt is that it allows more information to be packed into a figure--especially a multi-axes figure. The tradeoff is that it increases the likelihood of having figures that don't work in projected slides, and that have text that is smaller than the body text in a report.
In trying to set up the defaults for 2.0, we have the additional problem that mpl doesn't have good scaling mechanisms. Changing the font size often requires changing pad values that logically should scale with the font, but don't. And then there is the whole problem of the Axes position, which remains to be fixed to match the present combination of ticks, labels, etc., or any changes in them.

Maybe what we really need here is to have the full set of defaults tuned for the 12 pt case (probably with legend-medium, not small) and then a style that provides the corresponding set of size-related parameters all tuned for the 10 pt case.

@tacaswell
Copy link
Member

👍 to a 12pt and 10pt tuned styles so long as it does not take too much extra work.

@efiring
Copy link
Member Author

efiring commented May 23, 2016

The first step is just getting one of the two working. We are closest to the 12-pt version in our present defaults, but it still needs tweaking because of side effects of the outward ticks.

@efiring efiring force-pushed the legend_defaults branch from 7e2b888 to 6c4b973 Compare May 23, 2016 20:22
@tacaswell
Copy link
Member

I am going to merge this as-is.

It is clearly an improvement, looks decent (modulo the axes size issues which is being addressed else where).

@tacaswell tacaswell merged commit 182354b into matplotlib:v2.x May 28, 2016
@efiring efiring mentioned this pull request May 28, 2016
@efiring efiring deleted the legend_defaults branch June 23, 2016 18:19
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.

9 participants