How do I add axis title to a Dash/Plotly live-update script? Also a second question

Hi!

This is most probably an easy question, but without an answer! I’ve watched YouTube videos, looked at tutorials and NONE of them even bother to title their x and y axis. And the layout of a live-update script seems so different from a normal plotly.graphobjs that I can’t seem to do it off of my own intuition either.

Could someone please help?

# import stuff for paths and serials
import win32com.client
from pathlib import Path
import pythoncom

# import stuff for treating data
import numpy as np
import pandas as pd
import datetime

# import stuff for plotly and dash
import dash
from dash.dependencies import Output, Input
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
from collections import deque

picoVNACOMObj = win32com.client.Dispatch("PicoControl2.PicoVNA_2")

#print("Connecting VNA")
findVNA = picoVNACOMObj.FND()
#print('VNA ' + str(findVNA) + ' Loaded')

dll = picoVNACOMObj.DLLVer()
#print("DLL version: " + dll)
calibrationkit = Path("C:/Users/ayilarana/PycharmProjects/pythonProject/SF287.kit")
cali = picoVNACOMObj.SelectKit(calibrationkit, "1")
#print("Result " + str(cali))

enhance_averages = picoVNACOMObj.SetEnhance("aver", 100)
#print("Averages: " + enhance_averages)

calibration = Path("C:/Users/ayilarana/PycharmProjects/pythonProject/ring.cal")
ans = picoVNACOMObj.SelectCal(calibration)
#print("Result " + str(ans))

meas = picoVNACOMObj.Measure("S11")
#print("Result " + str(meas))

raw = picoVNACOMObj.GetData("S11", "logmag", 0)

splitdata = raw.split(',')
converteddata = np.array(splitdata)
converteddata = converteddata.astype(np.float)
x_frequency = converteddata[:: 2]
y_s11 = converteddata[1:: 2]

close = picoVNACOMObj.CloseVNA()
#print("closing of VNA " + str(close))

df = pd.DataFrame()
df.insert(0, "Frequency", x_frequency, True)
df.to_csv('test.csv', index=False)

app = dash.Dash(__name__)
app.layout = html.Div(
    [
        dcc.Graph(id='live-graph', animate=False),
        dcc.Interval(
            id='graph-update',
            interval=4000,
            n_intervals = 0
        ),
    ]
)

@app.callback(Output('live-graph', 'figure'),
        [Input('graph-update', 'n_intervals')])

def update_graph_scatter(n):

    df2 = pd.read_csv('test.csv')

    pythoncom.CoInitialize()
    picoVNACOMObj = win32com.client.Dispatch("PicoControl2.PicoVNA_2")

    #print("Connecting VNA")
    findVNA = picoVNACOMObj.FND()
    #print('VNA ' + str(findVNA) + ' Loaded')

    calibrationkit = Path("C:/Users/ayilarana/PycharmProjects/pythonProject/SF287.kit")
    cali = picoVNACOMObj.SelectKit(calibrationkit, "1")
    #print("Result " + str(cali))

    enhance_averages = picoVNACOMObj.SetEnhance("aver", 100)
    #print("Averages: " + enhance_averages)

    calibration = Path("C:/Users/ayilarana/PycharmProjects/pythonProject/ring.cal")
    ans = picoVNACOMObj.SelectCal(calibration)
    #print("Result " + str(ans))

    meas = picoVNACOMObj.Measure("S11")
    #print("Result " + str(meas))

    raw = picoVNACOMObj.GetData("S11", "logmag", 0)

    splitdata = raw.split(',')
    converteddata = np.array(splitdata)
    converteddata = converteddata.astype(np.float)
    x_frequency = converteddata[:: 2]
    y_s11 = converteddata[1:: 2]

    df2[f'{datetime.datetime.now()}'] = y_s11
    df2.to_csv('test.csv', index=False)

    close = picoVNACOMObj.CloseVNA()
    #print("closing of VNA " + str(close))

    data = go.Scatter(
            x=x_frequency,
            y=y_s11,
            name='S11 Parameters of Curling Probe',
            mode='lines',
            )

    return {'data': [data], 'layout': go.Layout(xaxis=dict(range=[min(x_frequency), max(x_frequency)]),
                                                yaxis=dict(range=[min(y_s11), max(y_s11)]), )}

if __name__ == '__main__':
    app.run_server(debug=True)

The second question is this:

If I set my interval at anything less than 4000ms, my code fails as my VNA (vector network analyzer) cannot seem to gather data fast enough to update my app. I think its a bottleneck with my code and the way I’m requesting data from my VNA. But how do I make it faster so that I can gather data and refresh my app graph in 1000ms or less?

Kind regards,