Home > Back-end >  matplotlib xrange is not according to the data
matplotlib xrange is not according to the data

Time:12-01

I'm trying to plot a graph in matplotlib where the X range goes from -15 to 100. I'm including the full code below.

import matplotlib.pyplot as plt

xlabel = "Field (mT)"
ylabel = "Frequency (GHz)"

headingszie = 22
labelsize   = 60
ticksize    = 50

field = [-15,-10,-5,0,10,20,30,40,50,60,70, 80, 90, 100]
frq0 = [1.08,2.26,5.37, 4.44,3.26,2.80,1.90,5.01,2.06,2.151,2.112, 2.112, 2.114, 2.118]

plt.figure(figsize=(15,15))
plt.scatter(field,frq0,color='orange',s=300)
plt.plot(field,frq0, color='orange',linewidth=4.0)
plt.xlabel(xlabel,fontsize=labelsize)
plt.ylabel(ylabel,fontsize=labelsize)
plt.tick_params(labelsize=ticksize)

plt.tight_layout()
plt.show()

The produced graph is shown here; In this, even though the X range goes from -15 to 100 the marking is only started from 0. This could be due to some internal aesthetics of matplotlib. Is there any way to override this? and start the marking from -20 ? Thank you for the help.

CodePudding user response:

The graph looks good to me. It doesn't have to show you all the markings and that's ok.

Still, if you want to show the minimum value, you can force it using xticks:

plt.xticks(np.arange(min(field), max(field) 10, 15.0))
  • Related