FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[DOC] Tick locators & formatters examples by rougier · Pull Request #7084 · matplotlib/matplotlib · GitHub

Repository navigation

[DOC] Tick locators & formatters examples - #7084

Merged
tacaswell merged 18 commits into
matplotlib:masterfrom
rougier:ticks
Sep 22, 2016
Merged

tacaswell merged 18 commits into
matplotlib:masterfrom
rougier:ticks

Conversation

rougier commented Sep 10, 2016 •
edited
Loading

Copy link
Copy Markdown
Member

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


rougier changed the title [DOC] Tick locators example [DOC] Tick locators & formatters examples Sep 10, 2016

NelleV commented Sep 10, 2016

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm not sure I understand what you mean

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

QuLogic Sep 15, 2016 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
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 commented Sep 11, 2016

Copy link
Copy Markdown
Member Author

@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 added this to the 2.0 (style change major release) milestone Sep 11, 2016

Copy link
Copy Markdown
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.

Copy link
Copy Markdown
Member

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

story645 commented Sep 12, 2016 •
edited
Loading

Copy link
Copy Markdown
Member

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 commented Sep 12, 2016 •
edited
Loading

Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
Member

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

rougier commented Sep 13, 2016

Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
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.

rougier commented Sep 14, 2016 •
edited
Loading

Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
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 commented Sep 14, 2016

Copy link
Copy Markdown
Member Author

Done.

Copy link
Copy Markdown
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 commented Sep 14, 2016 •
edited
Loading

Copy link
Copy Markdown
Member

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 commented Sep 14, 2016

Copy link
Copy Markdown
Member Author

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 ?

Copy link
Copy Markdown
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 commented Sep 14, 2016 •
edited
Loading

Copy link
Copy Markdown
Member Author
  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.

Copy link
Copy Markdown
Member

Yay! Mind updating the picture?

Copy link
Copy Markdown
Member


QuLogic commented Sep 15, 2016

Copy link
Copy Markdown
Member

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

QuLogic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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



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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We won't need these.

fontsize=15, transform=ax.transAxes)

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Won't need these.

Copy link
Copy Markdown
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 commented Sep 15, 2016

Copy link
Copy Markdown
Member Author

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

rougier commented Sep 17, 2016 •
edited
Loading

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Good points.

NelleV commented Sep 19, 2016

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member

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

tacaswell merged commit 5d54672 into matplotlib:master Sep 22, 2016

Copy link
Copy Markdown
Member

Thanks @rougier !

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

Copy link
Copy Markdown
Member

backported to v2.x as 45d54e9

QuLogic changed the title [MRG+1][DOC] Tick locators & formatters examples [DOC] Tick locators & formatters examples Oct 16, 2016
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL