-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[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
Conversation
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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. |
@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. |
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. |
|
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 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. |
@story645 And you need some data (i.e. some plot) to make it work, right ? |
Not exactly, I think that's where using the offset argument may come in. |
@story645 Coudl make a PR on my PR to show the IndexLocator case ? |
Thanks, I've updated the PR and the screenshot at the top. |
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. |
Done. |
Awesome! Can you also please add the name of the args for LinearLocator and LogLocator? 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? |
Yay! A few slight nitpicks (I'm almost sorry for this, but...):
|
No problem but at this point I think it's a matter of personal test:
|
|
Done. Didn't update screenshots at top. |
Yay! Mind updating the picture? |
I don't understand why |
There was a problem hiding this 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") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't need these.
+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 ;) |
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 |
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points.
Merge this as-is, clean up the fall-out later if needed. |
Thanks @rougier ! |
DOC: Tick locators & formatters examples
backported to v2.x as 45d54e9 |
This is an example showing the different tick locators (but the IndexLocator since I don't understantd how it works) and tick formatters.