import visa
import time
import numpy as np
import matplotlib.pyplot as plt

 
#plt.axis([0,30,0,30])
#plt.plot([1,2,3,4])
#plt.show()
 
rm=visa.ResourceManager();
print (rm.list_resources())
power_meter=rm.open_resource("GPIB0::4::INSTR")
print(power_meter)
power_meter.timeout=10000
 
data=np.array([])
 
for i in range(31):
    power_meter.write("D?")
    time.sleep(0.5)
    d=float(power_meter.read())*1e9
    data=np.append(data,d)
 
x=np.arange(0,15.5,0.5)
plt.axis([0,15,0,30])
plt.plot(data)
plt.grid(True)
plt.scatter(x,data)
plt.xlabel('time(sec)')
plt.ylabel('optical power (nW)')
plt.title('optical power meter data')
plt.show()