0

Reviewing my mistakes, I've modified my code:

My code is:

fig, axs = plt.subplots(nrows=2, ncols=1, sharex=True)
axs = axs.flatten()
axs[0].scatter(df["Xaxis"], df["Yaxis"], c=df['cmap'])
axs[0].plot(df["Xaxis"], df["Yaxis"],c='black')

My problem now is that my X-axis restart every 22 rows of my dataframe and my graph presents so many lines crossing from Xmax to Xmin. I'll appreciate any help.

My graph

Here's some reduced data:

df = pd.DataFrame({
'cmap':[2.17073,2.14109,2.16052,2.81882,2.29713,2.26273,2.26479,2.7643,2.5444,2.5027,2.52532,2.6778],
'xAxis':[10,100,1000,10000,10,100,1000,10000,10,100,1000,10000],
'yAxis':[2.17169E-4,2.15889E-4,2.10526E-4,1.53785E-4,2.09867E-4,2.07583E-4,2.01699E-4,1.56658E-4,1.94864E-4,1.92924E-4,1.87634E-4,1.58252E-4]})

1 Answers1

0

The way that I solved my problem is adding a column in my dataframe as:

dataframe['groups'] = np.floor_divide(dataframe.index, 22).astype(str)

and then join the two plots as:

fig, axs = plt.subplots(sharex=True)
axs = axs.flatten()
axs.scatter(df["Xaxis"], df["Yaxis"], c=df['cmap'])
dataframe.groupby('groups').plot(kind='line', x="Xaxis", y="Yaxis", ax=axs, c='black', legend=None)