Skip to content
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

putting tick labels in LaTex formatted scientific notation? #42

Closed
jbloom opened this issue Aug 11, 2017 · 2 comments
Closed

putting tick labels in LaTex formatted scientific notation? #42

jbloom opened this issue Aug 11, 2017 · 2 comments
Labels

Comments

@jbloom
Copy link

jbloom commented Aug 11, 2017

Is there a way to put tick labels in real scientific notation using LaTex formatting? I want something like 1e7 to appear as a 10 with the superscript exponent 7.

@has2k1
Copy link
Owner

has2k1 commented Aug 11, 2017

Yes, assuming you know the breaks.

df = pd.DataFrame({'x': [1, 10, 100, 1000, 10000, 100000]})

(ggplot(df)
 + geom_point(aes('x', 'x'))
 + scale_x_log10(labels=['$10^1$', '$10^3$', '$10^5$'])
)

Otherwise, you can write a function (takes breaks and returns labels enclosed in $$) to do the labelling.

def label_func(breaks):
    return ['$10^{}$'.format(int(np.log10(i))) for i in breaks]

(ggplot(df)
 + geom_point(aes('x', 'x'))
 + scale_x_log10(labels=label_func)
)

@has2k1 has2k1 closed this as completed Aug 11, 2017
@huguyuehuhu
Copy link

huguyuehuhu commented Sep 13, 2018

When label have Negative index, @has2k1 solution should be changed into:

def label_to_scentific_mode_func(breaks):
    return ['$10^{{{}}}$'.format(int(np.log10(i))) for i in breaks] 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants