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

# How to Plot Smooth Lines with non-aggregated data

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:

SCRIPT_REAL('

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.

• ###### 1. Re: How to Plot Smooth Lines with non-aggregated data

Hi Kara,

Using an Aggregate as an argument

FLOAT( MIN( [BT_Ceiling] ) )

would help to get a Table Calc

to work on a view.

I'm not sure about the expected result, though.

Yours,

Yuri

1 of 1 people found this helpful
• ###### 2. Re: How to Plot Smooth Lines with non-aggregated data

Thanks for the help! It validated the function, but it did not plot a smooth line - it's the exact same jagged one.

Any more suggestions?

• ###### 3. Re: How to Plot Smooth Lines with non-aggregated data

Hi Kara,

In the document you've been referred to

there is a notion of using a 'range-aware' Pill --

such as a Date/Datetime type or a Bin one --

to generate the additional 'densified' Marks on a view,

for which the interpolated values could be plotted.

I've been using a Tableau-generated Bin (Discrete aka Blue) Pill.

The flag Show Missing Values set for this (range-aware) Pill

is triggered the data padding (creating more Marks) on a view.