0

I've found a few solutions close to this but i can't get my axes to label correctly still. I'm missing something small.

I have a radioactive decay curve to be plotted as a straight line.

I have 2 lists of data, and i plot using scatter(hours,np.log(activity),color='red')

the y axis comes out as np.log(activity) as expected but i wish to make it just activity while maintaining the linear plot.

using a.yaxis.set_major_formatter(ticker.FormatStrFormatter("%d")) i can change the tick labels to whatever i want but i cant assign a list to the tick labels. if i replace %d with activity[0] for instance then all ticks take that value.

I hope it's clear here what im trying to do.

see plot here

All i want to do is multiply the y-axis ticks by np.exp(y-ticks)

cheers

1 Answer 1

1

I would plot scatter(hours, activity), then ax.set_yscale('log') to get it on a log scale, and finally ax.set_major_formatter(ScalarFormatter()) to show the tick labels as regular numbers (the default is scientific notation).

If you really have to plot log(activity) (for fitting purposes or something), the answer to your original question is:

ax.yaxis.set_major_formatter(FuncFormatter(lambda y, pos: "%.3f"%(np.exp(y))))

see https://matplotlib.org/api/ticker_api.html#matplotlib.ticker.FuncFormatter

Sign up to request clarification or add additional context in comments.

2 Comments

Your first point was my original method, however the other fitting im doing then doesn't display properly. the log scale axis messes up the linear fitting. The second point was the solution i was looking for, tyvm!
My approach in that situation is usually to do the linear fit to the log data, then plot the fit as exp(m*x + b) on the log scaled plot of the original data. Glad this other solution works for you though!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.