Skip to content

tight_labels #801

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

Closed
wants to merge 1 commit into from
Closed

tight_labels #801

wants to merge 1 commit into from

Conversation

leejjoon
Copy link
Contributor

This is my attempt to improve the situation of axis with too many ticks with overlapping ticklabels.
The overall idea is similar to tight_layout.
It calculates the fraction of the sum of ticklabel lengths (or heights) along the x-axis (or y-axis) over the axis length, and adjust the nbin value of tick locator until it satisfies some criteria.

Here is a simple usage.

fig, axes_list = plt.subplots(4, 4)
plt.tight_labels()
plt.tight_layout()

This PR is just to toss around ideas. It may have some problems with shared axes.
Also, I'm not quite happy with the current heuristics, and want to play with other heuristics.

@ivanov
Copy link
Member

ivanov commented Mar 27, 2012

this looks related to #776, which also uses a heuristic, but one based on just the number of subplots created by the subplots command.

@WeatherGod
Copy link
Member

I like this idea better. Haven't had a chance to look through it yet, but could it get extended to auto adjust font sizes or wrap text if we want a fixed number of tick labels, such as for bar graphs and other categorical plotting?

@leejjoon
Copy link
Contributor Author

@ivanov: Yes, we are trying to solve a same problem here, I believe. On the other hand, I think one thing that is better to be discussed is how we expose such functionality to the users, as your approach and mine is slightly different. My quick thought is that we may provide both .

@WeatherGod: Yes, we can adjust the font size, or we can rotate the text. Also, I think it would be good if there are several heuristics that a user can select.

@mdboom
Copy link
Member

mdboom commented Jun 1, 2012

This is a nice addition. Are there cases where #776 is provides a better solution than this or vice versa?

If we're going to adjust font sizes, that should be a clear option -- in most cases, I want my font sizes to exactly match the font sizes of the surrounding document, so I don't want them scaled automatically, though I can imagine cases where the user wouldn't care.

@WeatherGod
Copy link
Member

Besides documentation and tests, is there any reason why this PR should be held up? Would be nice to get this in before the feature freeze on the 20th.


min_nbin = self.major.locator._nbins

while self._get_label_occupy_fraction(renderer) < max_label_fraction:
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to put in a safeguard here from getting stuck in an infinite loop? Is that a likely occurrence?

@pelson
Copy link
Member

pelson commented Jan 9, 2014

PR is 2 years old so I'm closing it.

The concepts are good, but ideally this would be proposed via a MEP for non-technical discussion to take place before any implementation is attempted.

@pelson pelson closed this Jan 9, 2014
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.

6 participants