I am trying to graph data of different frequencies some of my data is 55H while the other dataset I have is 4Hz.

So far I have all the values graphed on the same timescale, I am now just trying to set my xticks, I have had no problem with the yticks, however when I try to set the xticks it causes graph to squash up see the image.

The code below is the function I used to graph the dataset, which produced the graph below this. As you can see the green line, my gaze targets have been squashed if I comment out


I get the graph I want but without the correct ticks.

Can't really figure out what's up, and to be honest, the code is pretty messy, as I have struggled to graph data of different lengths.

Help much appreciated

import sys
import csv
import os
import matplotlib.pyplot as plt
import matplotlib.ticker as plticker
from math import isclose
import matplotlib.transforms as mtransforms
from functools import reduce
from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA
import matplotlib.pyplot as plticker

# Function for location detection 

# You will need to merge data what ever sensor you are using with the GPS data on timestamp
# Pass your GPS start and end lat and lon and the merged dataframe to the function
def GPS_find_loc(gps_startLat, gps_startLon, gps_endLat, gps_endLon, df): 
    locList = []
    #dfnew = df[['latatude', 'longatude']].copy()
    #dfnew = dfnew.dropna().reset_index(drop=True)
    for index, row in df.iterrows():
        if isclose(row['latitude'], gps_startLat, abs_tol=1e-4) == True and isclose(row['longitude'], gps_startLon, abs_tol=1e-4) == True:

        elif isclose(row['latitude'], gps_endLat, abs_tol=1e-4) == True and isclose(row['longitude'], gps_endLon, abs_tol=1e-4) == True:
    Start = locList[0]
    End = locList[-1]
    return Start, End

def plotGaze(Loc, lat, lon, Par, location):

    time = df.timestamp[lon] - df.timestamp[lat]

    fig = plt.figure(figsize=(15,7.5))
    host = fig.add_subplot(111)

    par1 = host.twinx()
    par2 = host.twinx()
    par3 = host.twinx()

    host.set_xlabel("Time (s)")
    host.set_ylabel("Gaze targets")
    par1.set_ylabel("Pressure on Acc (bar)")
    par2.set_ylabel("Pressure (bar)")

    color1 = "g"
    color2 = "b"
    color3 = "y"
    color4 = "r"

    x1 = np.linspace(0, 1, len(df.objectName[lat:lon].dropna().reset_index(drop=True)))
    x3 = np.linspace(0, 1, len(df.HR[lat:lon].dropna().reset_index(drop=True)))

    mean = np.mean(df.HR.dropna().reset_index(drop=True))

    p1, = host.plot(x1, df.objectName[lat:lon].dropna().reset_index(drop=True), label='Object', color='g', linewidth=0.5)

    p2, = par1.plot(x1, df.pressureOnAccPeddle[lat:lon].dropna().reset_index(drop=True).rolling(13).median(), label='Acc pedel', color='b', linewidth=0.5)

    p3, = par2.plot(x1, df.pressure[lat:lon].dropna().reset_index(drop=True).rolling(13).median(), label='Acc pedel', color='y', linewidth=0.5)
# df.HR is at a lower frequency 
    p4, = par3.plot(x3, df.HR[lat:lon].dropna().reset_index(drop=True), label='Acc pedel', color='r', linewidth=0.5)

    par3.axhline(y=mean, label='Mean= ' + format(round(mean, 1)), color='r', linestyle='--', linewidth=0.5)

    lns = [p1, p2, p3, p4]

# Setting outer spines
    par2.spines['right'].set_position(('outward', 90))  
    par3.spines['right'].set_position(('outward', 40))     

    xlables = np.arange(0, time)


    host.set_xticklabels(xlables, fontsize='small')

    labels = [item.get_text() for item in host.get_yticklabels()]
    labels = ('IVI','Cluster','RearViewMirror','Others','RightSideViewMirror','Right_Others','Windshield','FrontalArea','Left_Others','LeftSideViewMirror')

    host.set_yticklabels(labels, color=color1,fontsize='small')




file_name_HR = "stackoverflowexample.csv"
pd.set_option('display.float_format', lambda x: '%.6f' % x)
df =  pd.read_csv(file_name_HR, sep=',', header=0) 

LatStartBrown, LonStartBrown =  53.279644, -9.069730
bExitlat, bExitlon = 53.278779, -9.069806
BrownStart, BrownEnd = GPS_find_loc(LatStartBrown, LonStartBrown, bExitlat, bExitlon, df)
df[BrownStart:BrownEnd].to_csv("C:/PhD Tests/Results/stackoverflowexample.csv") 
plotGaze("_Brown.png", BrownStart, BrownEnd, Par, "Brown")

My reputation isn't high enough to post the image but you can take a look below

Please find the data below https://drive.google.com/open?id=1zdayM5JWLLYLA_bokaWw8EVLzDRFlQ21


0 Answers