Skip to content

[DOC] Tick locators & formatters examples #7084

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 18 commits into from
Sep 22, 2016
Merged

Conversation

rougier
Copy link
Member

@rougier rougier commented Sep 10, 2016

This is an example showing the different tick locators (but the IndexLocator since I don't understantd how it works) and tick formatters.

tick-locators


tick-formatters

@rougier rougier changed the title [DOC] Tick locators example [DOC] Tick locators & formatters examples Sep 10, 2016
@NelleV
Copy link
Member

NelleV commented Sep 10, 2016

This looks great! Thanks for the addition to the gallery.

ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.tick_params(which='major', width=1.00, length=5)
ax.tick_params(which='minor', width=0.75, length=2.5, labelsize=10)
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit confusing, not being the default, but maybe it should be?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure I understand what you mean

Copy link
Member

Choose a reason for hiding this comment

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

I mean it might be confusing for users to see the documentation use this look, with different tick lengths/fontsizes for major/minor, when it's not really how it would look by default.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, now I get your point. The idea was to emphasize the fact that you can control major / minor ticks / labels separately and the different font sizes really suggest this (at least to me).

Since this is a submission to the gallery, is it important to enforce the defaults ?

Copy link
Member

Choose a reason for hiding this comment

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

The whole goal of this example is to show what you can do with axes and ticks. That means changing the default. I don't see how you could do something identical with the defaults. I also don't see how this could confuse the user: the example is well written and clear.

Copy link
Member

@QuLogic QuLogic Sep 15, 2016

Choose a reason for hiding this comment

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

Sorry, was confusing this with the other PR and where it was going.

Also, I thought it looked nice enough to be a default, but I think the time for changing that has passed.

@story645
Copy link
Member

Is there a way in the examples to more clearly show how multiple locator differes from maxN differed from auto? Like maybe change to a 1-10 range to have more wiggle room? Or use different scales-dunno, but I figure this image is at its most useful if readers don't necessarily have to read the code to get what it's trying to show.

@rougier
Copy link
Member Author

rougier commented Sep 11, 2016

@story645 You're right. Maybe 5 was not the best value to illustrate the different strategies. I'll try to play a bit more with the MaxN.

@tacaswell tacaswell added this to the 2.0 (style change major release) milestone Sep 11, 2016
@story645
Copy link
Member

Yay! Now maybe something with multiples of 2 for multiple locator? And possibly using the axis text to explain what the formatters are labeling as that might explain strformatter vs scaler formatter. Formatstrformatter and strmethod formatter seem to work exactly the same/do the same thing...so I'm confused there.

@tacaswell
Copy link
Member

FormatStrFormatter expects the old-style '%' based strings, StrMethodFormatter takes the new-style '{}' based format strings.

@story645
Copy link
Member

story645 commented Sep 12, 2016

Ugh...since python documentations says both of those are format strings, wouldn't it have made more sense to fold the functionality for both into one of those functions? For the same of this example though, then maybe add the format string to the label FormatStrFormatter('>%d<')?

@rougier IndexLocator seems to be MultipleLocator where the start value for the ticks isn't necessarily 0. So given plot(range(2, 20)) Multiplelocator with base=5 will yield 5, 10, 15, 20 whereas indexLocator can be given base=5 and offset=2 and therefore yield 2, 7, 12, 17. This is probably most useful for year plots where you want every 5 or 10.

This might also work with just base=5, as the main point is IndexLocator locates every 5th point (hence index) whereas MultipleLocator locates multiples of 5.

@rougier
Copy link
Member Author

rougier commented Sep 12, 2016

@story645 And you need some data (i.e. some plot) to make it work, right ?

@story645
Copy link
Member

Not exactly, I think that's where using the offset argument may come in.

@rougier
Copy link
Member Author

rougier commented Sep 13, 2016

@story645 Coudl make a PR on my PR to show the IndexLocator case ?

@story645
Copy link
Member

Instead of a PR, I can give you code:

ax.plot(range(5, 55), [0]*50, color='White')
ax.xaxis.set_major_locator(ticker.IndexLocator(base=5, offset=2))
ax.text(0.0, 0.25, "IndexLocator (base=5, offset=2)", fontsize=16, transform=ax.transAxes)

Since IndexLocator is counting off ticks, it only works when data gets plotted.
index

@rougier
Copy link
Member Author

rougier commented Sep 14, 2016

Thanks, I've updated the PR and the screenshot at the top.

@story645
Copy link
Member

I still think you should change some of the other examples-like change multiple locator to be multiples of 5 or something so it's really clear what it does. And possibly put the parameters in the text for each of the locators/formatters.

@rougier
Copy link
Member Author

rougier commented Sep 14, 2016

Done.

@story645
Copy link
Member

Awesome! Can you also please add the name of the args for LinearLocator and LogLocator?
(And I fully support you changing the IndexLocator code to something like base=0.5, offset=.25 if you want to keep everything on more or less the same scale)

Also, can you put the format strings you used for FormatStr formatter and for StrMethod formatter in parenthesis next to each, so FormatStr formatter(">%d<") and the like?

@story645
Copy link
Member

story645 commented Sep 14, 2016

Yay! A few slight nitpicks (I'm almost sorry for this, but...):

  1. please space out the formatters a bit since it's getting crowded (yes, my fault on account of wanting the args)
  2. add the arg name to LinearLocator
  3. reorder the Locators and Formatters to either match the docs or so that the ones that don't take args come first (so Auto, Null, then in increasing order of complexity and with similar ones grouped together)

@rougier
Copy link
Member Author

rougier commented Sep 14, 2016

No problem but at this point I think it's a matter of personal test:

  1. I think it's not too crowded
  2. There is no arg name in my call to LinearLocator
  3. It's only an example, so unless we want it somewhere in the doc, I think it's fine now, don't you think ?

@story645
Copy link
Member

  1. Compromise? For FixedLocator and FixedFormatter, can you space out the text so it follows PEP8 coding style about spaces after commas?
  2. numticks is the name of the first arg, and I think writing numticks=3 more explicitly gets across what's going on
  3. shrugs personal preference, but I think ordering goes a long way towards clarity

@rougier
Copy link
Member Author

rougier commented Sep 14, 2016

  1. Arrrggghhhh.... Ok, I'll do it even if I'm PEP8 allergic (cc @NelleV)
  2. Makes sense
  3. But more work for me (=PR appreciated)

Done. Didn't update screenshots at top.

@story645
Copy link
Member

Yay! Mind updating the picture?

@tacaswell
Copy link
Member

so
so2

@QuLogic
Copy link
Member

QuLogic commented Sep 15, 2016

I don't understand why FixedFormatter starts with a blank string, but the first tick still has a 0 on it?

Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

Should we use plt.subplots instead of individual plt.subplot?



plt.tight_layout()
# plt.savefig("tick-formatters.pdf")
Copy link
Member

Choose a reason for hiding this comment

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

We won't need these.

fontsize=15, transform=ax.transAxes)

plt.tight_layout()
# plt.savefig("tick-locators.pdf")
Copy link
Member

Choose a reason for hiding this comment

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

Won't need these.

@story645
Copy link
Member

+1 on @QuLogic's suggestion of using plt.subplots 'cause then you can just loop over the setup ax stuff trivially and that leaves the examples a lot cleaner and it becomes much more trivial to reorder them ;)

@rougier
Copy link
Member Author

rougier commented Sep 15, 2016

I think it's preferable to have subplot because it makes each sub-example self-contained. You can just copy and paste into your code and for me it's what example are useful for. The main point here are tick locators / formatters, it is not about subplot/subplots.

As for the empty string in FixedFormatter, I think this is a bug but I forgot to report.

@NelleV NelleV changed the title [DOC] Tick locators & formatters examples [MRG+1][DOC] Tick locators & formatters examples Sep 16, 2016
@rougier
Copy link
Member Author

rougier commented Sep 17, 2016

I opened issue #7122 about the FixedFormatter problem. In the meantime, it seems there's also a bug in MultipleLocator (same issue). PR #7123 has been proposed to fix the bug.

ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00))
ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25))
ax.xaxis.set_major_formatter(ticker.FuncFormatter(major_formatter))
ax.text(0.0, 0.5, "FuncFormatter(myfunc)", fontsize=15, transform=ax.transAxes)
Copy link
Contributor

Choose a reason for hiding this comment

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

FuncFormatter(lambda x, pos: "[%.2f]" % x) seems a better caption? Also, the minor_formatter function seems unused?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good points.

@NelleV
Copy link
Member

NelleV commented Sep 19, 2016

Are we waiting for #7122 and #7123 to be fixed or can we merge as is?

@tacaswell
Copy link
Member

Merge this as-is, clean up the fall-out later if needed.

@tacaswell tacaswell merged commit 5d54672 into matplotlib:master Sep 22, 2016
@tacaswell
Copy link
Member

Thanks @rougier !

tacaswell added a commit that referenced this pull request Sep 22, 2016
DOC: Tick locators & formatters examples
@tacaswell
Copy link
Member

backported to v2.x as 45d54e9

@QuLogic QuLogic changed the title [MRG+1][DOC] Tick locators & formatters examples [DOC] Tick locators & formatters examples Oct 16, 2016
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.

7 participants