Nonlinear scaling for gridlines in Python matplotlib

Viewed 147

I want to plot this data. enter image description here

like this enter image description here

The y-axis has the log scale, but the scaling of gridlines is nonlinear as shown in the picture above. I have two question

  1. How can I can make the y gridlines are like in the picture above
  2. How can I find the curve fitting fuction? My code is
df = pd.read_excel('BER_waterfall.xlsx',sheet_name='T21G03362')
cols = ['EnvVcc3_V','Temperatures']
df[cols] = df[cols].astype(str)

title1 = ''
ylabel1 = 'BER'
linestyle1 = 'none'

dfLTLV = df[df["Temperatures"].str.contains('-40') & df["EnvVcc3_V"].str.contains('3.1')]
fig, axes = plt.subplots(figsize=(6,5), dpi=100)
linewidth1 = 1.2
ms1 = 5

dfLTLV.plot(x='RxPower_dBm',y='BerMeasurement', linestyle=linestyle1,ax = axes, label='LTLV',title = title1, marker = 'D',grid = True,linewidth = linewidth1, ms = ms1)
axes.set_title(title1,pad=20, fontdict={'fontsize':24})
axes.set_xlabel('OSNR(dB)',fontdict={'fontsize':15})
axes.set_ylabel(ylabel1,fontdict={'fontsize':15})
axes.legend(loc='center', bbox_to_anchor=(1.15, 0.5),fontsize=12)
axes.tick_params(axis='both', labelsize=10)
axes.set_xscale('linear')
axes.set_yscale('log')
axes.set_ylim(1e-14,1e-2)
axes.set_xlim(-35,-24)

and plot is

enter image description here

Can some please direct me to where I can learn about making the nonlinear y gridlines and also for curve fitting for such data?

1 Answers

In your case you are looking for a way to plot the data in logarithmic scale. One way is to use the 'logy' argument:

dfLTLV.plot(x='RxPower_dBm',y='BerMeasurement', linestyle=linestyle1,ax = axes, label='LTLV',title = title1, marker = 'D',grid = True,linewidth = linewidth1, ms = ms1, logy=True)

Second way is using Matplolib.Axes set_yscale method:

ax.set_yscale('log')

for further reading:

https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_yscale.html

Related