Preventing axes from falling into scientific notation (authority 10) using matplotlib in Python on a semi-logical section

I read here ( How to prevent exponentially changing numbers in a Python matplotlib figure ) and here ( Matplotlib: disable ten ten powers in the log chart ) and tried to solve them to no avail.

How can I convert the y axis to display ordinary decimal numbers instead of scientific notation? Please note that this is Python 3.5.2.

enter image description here

Here is my code:

#Imports: import matplotlib.pyplot as plt possible_chars = 94 max_length = 8 pw_possibilities = [] for num_chars in range(1, max_length+1): pw_possibilities.append(possible_chars**num_chars) x = range(1, max_length+1) y = pw_possibilities #plot plt.figure() plt.semilogy(x, y, 'o-') plt.xlabel("num chars in password") plt.ylabel("number of password possibilities") plt.title("password (PW) possibilities verses # chars in PW") plt.show() 
+1
python matplotlib plot scientific-notation
Oct 31 '16 at 3:00
source share
1 answer

How do you want to display 10^15 ? How 1000000000000000 ?! Another answer relates to the default formatting format, when you switch to the log scale, use LogFormatter , which has a different set of rules. You can go back to ScalarFormatter and disable the offset

 import matplotlib.pyplot as plt import matplotlib.ticker as mticker plt.ion() possible_chars = 94 max_length = 8 pw_possibilities = [] for num_chars in range(1, max_length+1): pw_possibilities.append(possible_chars**num_chars) x = range(1, max_length+1) y = pw_possibilities #plot fig, ax = plt.subplots() ax.semilogy(x, y, 'o-') ax.set_xlabel("num chars in password") ax.set_ylabel("number of password possibilities") ax.set_title("password (PW) possibilities verses # chars in PW") ax.yaxis.set_major_formatter(mticker.ScalarFormatter()) ax.yaxis.get_major_formatter().set_scientific(False) ax.yaxis.get_major_formatter().set_useOffset(False) fig.tight_layout() plt.show() 

example output

See http://matplotlib.org/api/ticker_api.html for all available Formatter classes.

(this image is created from the 2.x branch, but should work with all the latest version of mpl)

+1
Oct 31 '16 at 3:46
source share



All Articles