0

I have a python script which reads data from database and draws several plots. In some of these plots, I get unwanted abbreviations (unwanted offset), as It is shown in this image:

pylab plot unwanted abbreviation

Given numbers are between 1.0020 and 1.0030. However, as it is shown, they are given in another range, and the plot asks to add 9.99e-1.

I have implemented a plot function in python:

import matplotlib.pyplot as pyplot
from matplotlib.backends.backend_pdf import PdfPages

def plot(x_list, y_list, xlable, ylable, legend, legend_place='best',
         pdf_name=None, show=True, figure_num=None):
    figure = pyplot.figure(num=figure_num, figsize=(6, 6), dpi=80)
    figure.add_subplot(111)
    pyplot.xlabel(xlable)
    pyplot.ylabel(ylable)
    pyplot.tight_layout()

    line_spec = ['b.-', 'rx-', 'go-', 'md-']

    for i, x in enumerate(x_list):
        y = y_list[i]
        pyplot.plot(x, y, line_spec[i])

    pyplot.legend(legend, legend_place)
    if pdf_name is not None:
        pyplot.title(pdf_name)
        pdf = PdfPages(pdf_name + '.pdf')
        pdf.savefig()
        pdf.close()

    if show:
        pyplot.show()

Can I add something to it to prevent those offsets?

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
am.rez
  • 876
  • 2
  • 12
  • 24
  • 1
    Have you tried the solutions suggested here: http://stackoverflow.com/questions/14775040/matplotlib-axis-label-format ? – cphlewis Jan 23 '16 at 00:47
  • Thank you, my solution is written in the question of that link! The problem is English is not my first language and I didn't know this is called "offset". `ax1.ticklabel_format(axis='y', style='sci', useOffset=False)` solved my problem. – am.rez Jan 23 '16 at 10:14

1 Answers1

2

You need to get the axis and set off Scientific notation, like that:

ax = pyplot.gca()

#set off Scientific notation from Y-axis
ax.get_yaxis().get_major_formatter().set_useOffset(False)
ax.get_yaxis().get_major_formatter().set_scientific(False)

#set off Scientific notation from X-axis
ax.get_xaxis().get_major_formatter().set_useOffset(False)
ax.get_xaxis().get_major_formatter().set_scientific(False)
vrjuliao
  • 31
  • 2