0

I have a script that reads a database and retrieves timstamps and two values for each timestamp (level and altitude) here:

    dbc = r'Database Connection'
    QueryTable = "QueryTable"
    sql= "Identifier="+NWFID

    #Setup arrays
    x = []
    y = []
    y1 = []


    
    fields = ["datetime", "WL_LSD", "WL_Altitude_NAVD88"]


    with arcpy.da.SearchCursor(dbc, fields, where_clause = sql, sql_clause=(None, 'ORDER BY "datetime"')) as rows:
        for row in rows:
            x.append(row[0])
            y.append(row[1])
            y1.append(row[2])
            

fig, ax1 = plt.subplots() 

ax1.set_xlabel('Date') 
ax1.set_ylabel('LSD', color = 'red') 
plot_1 = ax1.plot(x, y, color = 'red', label='GWL (LSD)') 
ax1.tick_params(axis ='y', labelcolor = 'red')

ax2 = ax1.twinx() 

ax2.set_ylabel('Altitude', color = 'blue') 
plot_2 = ax2.plot(x, y1, color = 'blue', label = 'GWL (NAVD88') 
ax2.tick_params(axis ='y', labelcolor = 'blue') 

lns = plot_1 + plot_2
labels = [l.get_label() for l in lns]
plt.legend(lns, labels, loc=0)


plt.show()

I want to plot them on dual y-axes where it appears to be same line but using twinx() in my script causes noticeable offset in the graph below. Any suggestions

enter image description here

  • Hi, what do you mean by "noticeable offset"? I don't see anything strange. Also, provide please [MRE](https://stackoverflow.com/help/minimal-reproducible-example) with only relevant code and data. – My Work Jul 31 '23 at 18:53
  • I guess there is an offset in the data. What does `np.unique(np.array(y) - np.array(y1))` return ? – paime Jul 31 '23 at 22:00

0 Answers0