question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I transform tick labels without explicitly specifying breaks?

See original GitHub issue

Let’s say I have a scatter plot where the x-axis date is pandas.Timestamp objects. By default, plotnine renders the x tick labels on my plot such such that they run into each other.

I’d like to do an arbitrary transformation on the x-axis tick labels. For example, I’d like the tick labels to be blank except for the first day of the year, in which case I want the tick label to just be the year, so "2017-03-04" would transform to "", and "2016-01-01" would transform to "2016".

However, I don’t want to explicitly specify the breaks. Instead, I want plotnine to use its default algorithm for determining where to put the breaks.

Is this possible to do with plotnine?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
has2k1commented, Jul 11, 2017

Re-opened to serve as a reminder for a tutorial section on date labels and breaks.

1reaction
lorincommented, Jul 11, 2017

That’s pretty close, but not quite what I wanted. However, it did help me figure out what I really wanted was this:

+ scale_x_datetime(labels=lambda lst: [x.year if x.month==1 and x.day==1 else "" for x in lst])

As an aside, the scale docs describe the labels argument as a list, specifically:

labels (list, optional) – List of str. Labels at the breaks.

However, given the answer above, it appears that the labels argument can also be a callable that takes a list (array_like?) of breakpoints as input and returns a list of strings as output.

Should the docs be updated? If so, I’m willing to submit a PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conditional Formatting ggplot label ticks without explicitly ...
You can use the technique linked in the duplicate post and provide separate lists for the colour and face arguments:
Read more >
Changing Axes
To adjust the number of minor ticks, you just change the number of minor breaks using the minor_breaks argument of the continuous scale...
Read more >
Customizing Axes in D3.js - Glenn Henshaw
A beginners guide to unpacking and customizing the elements of a D3 axis ... tickSize(); Attributes of the .domain <path> element; Tick labels:...
Read more >
ggplot2 axis ticks : A guide to customize tick marks and labels
Change the order of items; Change tick mark labels; Choose which items to display ... a character or numeric vector specifying which breaks...
Read more >
10 Position scales and axes | ggplot2
In this example the y aesthetic is not specified by the user. ... It covers limits, breaks, and labels in Section 10.3.1 and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found