Sitz Blogz
Sitz Blogz

Reputation: 1061

Big data multiple plots, multiple web pages Plotly

I am trying to work with big data plotting around 20 plots on plotly and embed them on web page. I can very well plot individual plots with username and one api_key that found in the profile.

The Problem comes is when: I have to rerun all the 20 plots with python program after interval of every 15 mins and every time I am getting new windows. Instead I need the same plot to update/redraw.

How do I get that? I tried reading the plot.ly document and also few tutorials outside. Cannot find how to get it done. Can anyone please help me with steps or refer me to some document where I can know how to work with multiple plots that will update at same time.

I am following the steps given in plotly tutorial not sure if I should use stream_ids ? Or can I create a new api_key for every plot ?Confused !!! Thanks in Advance for the suggestions.

Edit: I could make access tokens and Initiate the credentials from the following tutorial.

The code below works perfect: But now I am looking for required fixing in the below code by trying to minimize the code with annotations and where to include the streaming API Access Tokens while having sizable scatter plots ?

import plotly.plotly as py  
import plotly.tools as tls   
from plotly.graph_objs import *

import csv
import pandas as pd
import numpy as np

df =  pd.read_csv('finally.csv')
df1=df[['NAME','COUNT']]

sizemode='area'

sizeref=df1['COUNT'].max()/1000

def Trace(X,PLACE,sizes):
    return Scatter(
        x=X['NAME'],
        y=X['COUNT'].sum(),
        name=PLACE,
        mode='marker',
        marker=Marker(
            line=Line(width=0.9),   
            size=sizes,
            sizeref=sizeref,
            opacity=0.9,
        )
    )
data=Data()

for PLACE, X in df1.groupby('NAME'):    
    sizes=X['COUNT'].sum()/1000     
    data.append(Trace(X,PLACE,sizes))

title = "Fig 1.1 : All NAMES"
x_title = "Names".format()
y_title = "Count"

# Define a dictionary of axis style options
axis_style = dict(     
    zeroline=False,       # remove thick zero line
    gridcolor='#FFFFFF',  # white grid lines
    ticks='outside',      # draw ticks outside axes 
    ticklen=8,            # tick length
    tickwidth=1.5         #   and width
)

# Make layout object
layout = Layout(
    title=title,             # set plot title
    plot_bgcolor='#EFECEA',  # set plot color to grey
    xaxis=XAxis(
        axis_style,      # add axis style dictionary
        title=x_title,   # x-axis title
    ),
    yaxis=YAxis(
        axis_style,      # add axis style dictionary
        title=y_title,   # y-axis title
    ),
    showlegend=False, 
)
fig = Figure(data=data,layout=layout)

plot_url=py.plot(fig,filename=' plotting')

Upvotes: 0

Views: 1779

Answers (1)

neda
neda

Reputation: 1019

In plot/ iplot there is 'fileopt' option which should help you. For example, if you would want to add new traces to your existing data you can run

plot_url = py.plot(fig, filename='my-file', fileopt='append')

You're right it is not well documented yet. But if you run help(py.plot) you would get a small document on it as follow:

plot(figure_or_data, validate=True, **plot_options)
Create a unique url for this plot in Plotly and optionally open url.

plot_options keyword agruments:
filename (string) -- the name that will be associated with this figure
fileopt ('new' | 'overwrite' | 'extend' | 'append') -- 'new' creates a
    'new': create a new, unique url for this plot
    'overwrite': overwrite the file associated with `filename` with this
    'extend': add additional numbers (data) to existing traces
    'append': add additional traces to existing data lists
world_readable (default=True) -- make this figure private/public
auto_open (default=True) -- Toggle browser options
    True: open this plot in a new browser tab
    False: do not open plot in the browser, but do return the unique url

Upvotes: 1

Related Questions