Home > Blockchain >  How to remove exponents from axis matplotlib
How to remove exponents from axis matplotlib

Time:01-30

I would like to know if there is a way to remove 1e12 and 1e-6 on each axis. I would like to keep only the integer.

h = 6.62607015E-34
c = 299792458
k = 1.380649E-23
T = 3600

Lambda = np.linspace(0.01, 5,500)*10**-6


def flux(h,c,Lambda,T,k):
    return ((2*3.14*h*c**2) / (Lambda**5)) * 1/(math.e**( (h*c)/ (Lambda*k*T) ) -1)


plt.plot(Lambda, flux(h,c,Lambda,T,k))

CodePudding user response:

You can change the tick labels on the x and y axis by using the xticks and yticks methods in matplotlib. You can set the tick locations and the corresponding labels, or set the tick locations and have matplotlib automatically format the labels. Here's an example of the latter:

import numpy as np
import math
import matplotlib.pyplot as plt

h = 6.62607015E-34
c = 299792458
k = 1.380649E-23
T = 3600

Lambda = np.linspace(0.01, 5, 500) * 10**-6

def flux(h, c, Lambda, T, k):
    return ((2*math.pi*h*c**2) / (Lambda**5)) * 1/(math.e**( (h*c)/ (Lambda*k*T) ) -1)

plt.plot(Lambda, flux(h, c, Lambda, T, k))
plt.xlabel('Wavelength (µm)')
plt.ylabel('Flux (W/m^2)')

plt.gca().xaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))
plt.gca().yaxis.set_major_formatter(plt.FormatStrFormatter('%.0f'))

plt.show()

This will format the x and y axis tick labels to show only integers.

  • Related