3 Replies Latest reply on Dec 29, 2018 2:49 PM by Yuriy Fal

    How to Plot Smooth Lines with non-aggregated data

    Kara Combs

      Please see this post as a reference: How to create a smoothed line chart with Tableau & Python (detailed guide)


      I want to smooth a jagged line - I know why most people recommend not doing this, but I am required to do this.


      I attempted to apply this method to my data, but I believe the issue is with my data - so I was hoping to figure out how to fix it so that it wouldn't be an issue anymore. I just want to plot two quantities as a line graph, right now their name are [BT_Ceiling] and CNT([F7]).

      [BT_Ceiling] just applies a ceiling function to the values from [BT] (which is in my original data) - the range for this is all the whole numbers in [0,24] inclusive.

      CNT([F7]) is expressed as a percentage and count the number of data points that falls in each "bin" (for lack of a better word) based on the range created from [BT_Ceiling].


      The code I attempted to use for the smoothing function is as follows:


      import scipy.interpolate as interpolate


      X_all=_arg1 #assigning date dimension to x axis

      y_all=_arg2 #assigning our KPI measure to y axis


      y=[i for i in y_all if i is not None] #getting rid from Nones for y

      X=[i[0] for i in enumerate(X_all) if i[1] is not None] #getting list of indexes for X without Nones


      Xsmooth=list(range(0,len(X_all))) #generation full list of indexes for X

      ysmooth=interpolate.pchip_interpolate(X,y,Xsmooth) #interpolation (here i used pchip, but depending on source data, other function can be used, like spline)


      result=[round(i,10) for i in ysmooth] #rounding to fit in output JSON

      return result

      ', FLOAT([BT_Ceiling]),COUNT([F7]))


      I am having an issue with the bolded sections since the data is aggregate and non-aggregate. I've also attached a packaged workbook f what I am working with. I am running Tableau 2018.2.3.


      Thanks in advance!