python - 2 y-axis graph with x-axis as date and time . x value and y value data not showing on mouse point -


i created 2 y-axises (y, y1) graph x-axis date , time. while pointing graph y , x showing me data of x , y1. here code proof:

import sqlite3,time,datetime,os import numpy np import matplotlib.pyplot plt matplotlib import dates import matplotlib.dates mdates matplotlib import style style.use('ggplot')  def bytedate2num(fmt):     def converter(b):         return mdates.strpdate2num(fmt)(b.decode('ascii'))     return converter conn = sqlite3.connect("datas.db") c = conn.cursor() sql= "select timestap,date,val,num table" grapharray = [] temp=0 row in c.execute(sql):     if temp > int(row[0]):         continue     else:         temp=int(row[0])     grapharray.append(row[1]+','+row[2]+','+row[3])  date_converter = bytedate2num("%y-%m-%d %h:%m:%s") date_formatter = dates.dateformatter('%m/%d %h:%m') datestime, val, num= np.loadtxt(grapharray,delimiter=',', unpack=true,converters={ 0: date_converter}) fig = plt.figure() fig_size = plt.rcparams["figure.figsize"] fig_size[0] = 15 fig_size[1] = 12 fig, ax1 = plt.subplots() ax1.plot_date(datestime, val, 'g-') ax1.xaxis.set_major_formatter(date_formatter) plt.xticks(rotation=45) tl in ax1.get_yticklabels():     tl.set_color('g') ax2 = ax1.twinx() ax2.plot_date(datestime, num, 'r-') ax2.yaxis.set_label_position("right") tl in ax2.get_yticklabels():     tl.set_color('r') fig.autofmt_xdate() plt.show()  

enter image description here enter image description here

sample data

timestamp date num val

1461685551626 2016-04-26 15:45:51 20.884 5

1461685572550 2016-04-26 15:46:12 1.009 5

1461685573560 2016-04-26 15:46:13 0.09 5

1461685551140 2016-04-26 15:45:51 22.24 5

1461685578914 2016-04-26 15:46:18 1.061 7

1461685573914 2016-04-26 15:46:13 1.061 7

1461685560734 2016-04-26 15:46:00 20.849 7

1461685581587 2016-04-26 15:46:21 0.736 7

1461685582334 2016-04-26 15:46:22 0.058 7

1461685582393 2016-04-26 15:46:22 0.057 7


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -