cancel
Showing results for 
Search instead for 
Did you mean: 
intapiuser
Community Team Member
Community Team Member
Wanted to alter the thickness of the lines in your series, add markers to your lines, and make them dashed or dotted? The plot.ly library support on Sisense for Cloud Data Teams' Python/R integration allows you to tailor these parameters to your heart's desire!

For reference, here are the first few rows of our SQL output. This is data from a hypothetical gaming company
And below is the annotated Python 3.6 code! Note we need to first pivot the data such that each series gets its own column. More information on that can be found here. Also, plot.ly has great documentation going into different examples. Much of the below options were outlined in the documentation itself!
# SQL output is imported as a dataframe variable called 'df'
# Import pandas to use dataframe objects
import pandas as pd

# Import plot.ly viz libraries
import plotly.plotly as py
import plotly.graph_objs as go

# Pivot data. Details on how to do this here https://community.periscopedata.com/t/q5gk76/pivoting-and-melting-dataframes
df=pd.pivot_table(df,index='week',columns='source',values='count')
df=df.reset_index()

# Create traces
# Refer to https://plot.ly/python/line-charts/ for more options

admob_trace = dict(
    x = df.week,
    y = df['admob'],
    mode = 'lines',
    type = 'scatter',
    name = 'admob',
    line = dict(shape = 'linear', color = 'rgb(205, 12, 24)', width= 4, dash = 'dash'),
    connectgaps = True
)
leadbolt_trace = go.Scatter(
    x = df['week'],
    y = df['leadbolt'],
    mode = 'lines+markers',
    name = 'leadbolt',
    line = dict(shape = 'linear', color = 'rgb(10, 12, 240)', dash = 'dash'),
    marker = dict(symbol = "star-diamond", color = 'rgb(17, 157, 255)',size = 12),
    connectgaps = True
)
organic_trace = go.Scatter(
    x = df.week,
    y = df['organic'],
    mode = 'lines',
    name = 'organic',
    line = dict(shape = 'linear', color = 'rgb(10, 120, 24)', dash = 'dot'),
    connectgaps = True
)
tapjoy_trace = go.Scatter(
    x = df['week'],
    y = df['tapjoy'],
    mode = 'lines',
    name = 'tapjoy',
    line = dict(shape = 'linear', color = 'rgb(100, 10, 100)', width = 2, dash = 'dot'),
    connectgaps = True
)

# Setting up the layout settings in the "layout" argument
layout =  dict(
    xaxis = dict(title = 'Week'),
    yaxis = dict(title = 'Source'),
    margin = dict(
        l=70,
        r=10,
        b=50,
        t=10
    )
)
data = [admob_trace, leadbolt_trace, organic_trace, tapjoy_trace]

fig =  go.Figure(data = data, layout=layout)

# Use Periscope to visualize a dataframe, text, or an image by passing data to periscope.table(), periscope.text(), or periscope.image() respectively.
periscope.plotly(fig)

Prefer R Plot.ly? Here's the code for that!
# SQL output is imported as a dataframe variable called 'df'
# Use Periscope to visualize a dataframe or show text by passing data to periscope.table() or periscope.text() respectively. Show an image by calling periscope.image() after your plot.

# Use tidyr to pivot the data. We want a column per series
library(tidyr)
# Use plot.ly for visualziation
library(plotly)

# Pivoting data, see this post for further details https://community.periscopedata.com/t/q5gk76/pivoting-and-melting-dataframes
df=spread(df,source,count)

admob_trace <- df$admob
leadbolt_trace <- df$leadbolt
organic_trace <- df$organic
tapjoy_trace <- df$tapjoy

x <- df$week

data <- data.frame(x, admob_trace, leadbolt_trace, organic_trace, tapjoy_trace)

# Check out Plot.ly's documentation to find more options! https://plot.ly/r/reference/

p <- plot_ly(data, x = ~x) %>%
  add_trace(y = ~admob_trace, name = 'admob', type = 'scatter', mode = 'lines',
            line = list(shape = 'linear', color = 'rgb(205, 12, 24)', width= 4, dash = 'dash'),
            connectgaps = TRUE) %>%
  add_trace(y = ~leadbolt_trace, name = 'leadbolt',type = 'scatter', mode = 'lines+markers',
            line = list(shape = 'linear', color = 'rgb(10, 12, 240)', dash = 'dash'),
            marker = list(symbol = "star-diamond", color = 'rgb(17, 157, 255)',size = 12),
            connectgaps = TRUE) %>%
  add_trace(y = ~organic_trace, name = 'organic', type = 'scatter', mode = 'lines',
            line = list(shape = 'linear', color = 'rgb(10, 120, 24)', dash = 'dot'),
            connectgaps = TRUE) %>%
  add_trace(y = ~tapjoy_trace, name = 'tapjoy', type = 'scatter', mode = 'lines',
            line = list(shape = 'linear', color = 'rgb(100, 10, 100)', width = 2, dash = 'dot'),
            connectgaps = TRUE) %>%
  layout(xaxis = list(title = 'Week'), yaxis = list(title = 'Source'))

periscope.plotly(p)
Version history
Last update:
‎03-02-2023 09:33 AM
Updated by:
Contributors
Community Toolbox

Recommended quick links to assist you in optimizing your community experience:

Developers Group:

Product Feedback Forum:

Need additional support?:

Submit a Support Request

The Legal Stuff

Have a question about the Sisense Community?

Email [email protected]

Share this page: