Wrong values on X-Axis and Y-Axis

Hi All,

actually I try to create an application that should bring physicians and corona patients together. A patient can provide vital data and a physican can evaluate this in information in order to support and monitor patients in quarantine.

For this reason i want to track and visualize body temperature over a period of time. On my database I have stored temperature and measuring time. For loading the data I use a script called “vital_data_visualizer.py”

def get_vital_data(patient_id):
    patient = Patient.objects.get(pk=patient_id)
    raw_vital_data = VitalData.objects.filter(patient=patient)

    data = []

    for vital_data in raw_vital_data:
        dict = {}
        dict['temperature'] = vital_data.body_temperature
        dict['measuring_time'] = vital_data.body_temperature_measuring_time
        data.append(dict)

    return data

def create_df(patient_id):

    data = get_vital_data(patient_id)

    #create DataFrame
    df = pd.DataFrame(data)
    df['measuring_time'] = pd.to_datetime(df['measuring_time'])
    print(df.head())

    return df

In my view I create the figure and the glyph. Following the code snippet:

 source = ColumnDataSource(vital_data_visualizer.create_df(patient_id))

    #Create Figure
    plot = figure(title='Fever Course', x_axis_type='datetime')
    plot.line('temperature', 'measuring_time', color='red', line_width=5, source=source)

    script, div = components(plot)

The created view looks like this:

So my question is: How can I change the “values” on the x-axis from nanoseconds to days?
The values on y-axis are to high. Basically it should show the body temperature in degree centigrade (e.g. 38.2 or 39.0 etc.).

I am very thankful for any hint or help.

Greetings, Paul

PS: I hope this post was not too bad… It is my first one ever in a community

Hi @PGS please edit your post to use code formatting so that the code is intelligible (either with the </> icon on the editing toolbar, or triple backtick ``` fences around the code blocks)

Thank’s for your advice!

Based on a quick scan, is it possible you’ve swapped the x- and y- axis data in your call to the line function?

Basically, it looks like the “too-high” y-axis values are timestamps in units of the Unix epoch and the x-axis values are temperatures in degrees Centrigrade, reformatted because you have a datetime axis. I think this is consistent with the code where you call the line function with the temperature column as the first argument and the date-time as the second.

plot.line('temperature', 'measuring_time', color='red', line_width=5, source=source)

1 Like

Hi _jm, thank’s for your hint! I don’t know how, but i have not seen this obvious mistake.

BR, PGS