0

In the below script, if I run it without setting y axis range, the final plot is the following:

enter image description here

If I set the y-axis range via:

plt.ylim(-941.510, -941.505)

or via:

axes = plt.gca()
axes.set_ylim([-941.510, -941.505])

I get the following:

enter image description here

The tics on the y-axis do not longer appear as -941.495, -941.500, etc but in a scale, that is to be multiplied by the number given in the left corner (-9.415e2).

How could be achieved a similar y-axis configuration as the 1st plot, where there is no multiplication by a factor?

Code:

import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties

# Intial candidates for fit:
E0_init = -941.510817926696
V0_init = 63.54960592453
B0_init = 76.3746233515232
B0_prime_init = 4.05340727164527

def BM(x, E0, V0, B0, B0_prime):

        return  E0+ (2.293710449E+17)*(1E-21)*( (9.0/16.0)*(V0*B0) * (  (((V0/x)**(2.0/3.0)-1.0)**3.0)*B0_prime  + ((V0/x)**(2.0/3.0)-1)**2  *  (6.0-4.0*(V0/x)**(2.0/3.0))  ))

# A variable:
FU_Vat = 18.0

# Data:
V_Vate_W, E_Vate_W = np.loadtxt('./compilation_EOS.out', skiprows = 1).T
E_Vate_W = E_Vate_W/FU_Vat
V_Vate_W = V_Vate_W/FU_Vat


init_vals = [E0_init, V0_init, B0_init, B0_prime_init]
popt_Vate_W, pcov_Vate_W = curve_fit(BM, V_Vate_W, E_Vate_W, p0=init_vals)


# Plotting the fitting curves:
#          the scattered points: 
p7 = plt.scatter(V_Vate_W, E_Vate_W, color='green', marker="^", facecolors='none', label='', s=100)
p8, = plt.plot(V_Vate_W, BM(V_Vate_W, *popt_Vate_W), 'k--', label='')

fontP = FontProperties()
fontP.set_size('small')

plt.legend((p7, p8 ),("data", "fit"  ), prop=fontP)

#axes = plt.gca()
plt.xlabel('x')
plt.ylabel('y')
#axes.set_ylim([-941.510, -941.505])
#plt.ylim(-941.510, -941.505)
plt.show()
DavidC.
  • 669
  • 8
  • 26
  • 1
    The easiest way is to use `plt.ticklabel_format(useOffset=False)` as pointed out in [this answer](https://stackoverflow.com/a/43804704/4124317) to the second duplicate question. – ImportanceOfBeingErnest Jul 26 '17 at 10:01
  • 1
    Mind that the number that appears is an offset, the ticklabels are *not* "multiplied by the number given in the left corner", but the number on top needs to be *added* to the ticklabels. – ImportanceOfBeingErnest Jul 26 '17 at 10:05
  • @ImportanceOfBeingErnest Thank you so much for your great help :) I also totally agree with the fact that the number on the corner was to be added (and not multiplied) to the ticklabels – DavidC. Jul 26 '17 at 15:13

0 Answers0