run to see iplot option 'help(df.iplot)' """ import utils import preprocessing.arousal as paro import preprocessing.pre_utils as pu from preprocessing.iaps import iaps # Standard plotly imports import plotly import plotly.io as pio import plotly.plotly as py import plotly.graph_objs as go from plotly.offline import iplot, init_notebook_mode import plotly.figure_factory as ff # Using plotly + cufflinks in offline mode import cufflinks cufflinks.go_offline(connected=True) init_notebook_mode(connected=True) from sklearn.preprocessing import StandardScaler #%% get data data_df = utils.load_object('pd_for_train.pkl') arousals = utils.load_object('arousal.pkl') arousals_list = arousals['arousal'].tolist() data_df = pu.match_label_with_sample(data_df, arousals_list) #%% # scatter plot matrix #fig = data_df[['mean','max','median','min','skew']].reset_index(drop=True).scatter_matrix(asFigure=True) #plotly.offline.plot(fig)
from pandas.core.base import PandasObject from datetime import datetime # Setting pandas dataframe display options pd.set_option("display.max_rows", 20) pd.set_option('display.width', 800) pd.set_option('max_colwidth', 800) # Set plotly offline init_notebook_mode(connected=True) # Set matplotlib style plt.style.use('seaborn') # Set cufflinks offline cf.go_offline() # Defining today's Date from datetime import date today = date.today() from pandas_datareader import data as pdr import yfinance as yf yf.pdr_override() # <== that's all it takes :-) import PortfolioLab as pl # %% # download dataframe using pandas_datareader data = pdr.get_data_yahoo("^GSPC", start="1970-12-21",
# # 2) Pour n entier naturel non nul, on pose $u_n = H_n − ln(n)$ et $v_n = H_n − ln(n + 1)$. Montrer que les suites $(u_n)$ et $(v_n)$ convergent vers un réel γ. # In[1]: # Import pour plotter de manière facile import pandas as pd from ipywidgets import interact, interactive, fixed, interact_manual, IntSlider # Standard plotly imports import chart_studio.plotly as py import plotly.graph_objs as go from plotly.offline import iplot, init_notebook_mode # Using plotly + cufflinks in offline mode import cufflinks as cf cf.go_offline(connected=False) init_notebook_mode(connected=False) # In[4]: from math import log nMax = 100 logN = [1 + log(n) for n in range(1, nMax + 1)] logNPlus1 = [log(n + 1) for n in range(1, nMax + 1)] Hn = [1. / 1.] for k in range(2, nMax + 1): Hn.append(Hn[-1] + 1. / k) #Pour tracer
class CompressAlg(): mypath = 'excelFolder/' cf.go_offline() def __init__(self): pass def getRnSData(self, fileName, SGwd_length, SGpolyOrd): t = [] v = [] pltData = [] data, times = fT.readCSV(fileName) for i in range(len(data)): t.append(i) v.append(float(data[i])) sgf = savgol_filter(data, SGwd_length, SGpolyOrd) R2_RnS = round(mthT.coeff_of_determination(np.array(data), sgf), 3) #print(times) pltData += [ go.Scatter( x=times, # assign x as the dataframe column 'x' y=v, name='Raw', mode='lines', marker=dict(size=5, color='rgba(0,0,0,0.8)'), line=dict(width=8, ) # ============================================================================= # ), # go.Scatter( # x=times, # assign x as the dataframe column 'x' # y=sgf, # name='S-Gf: R2:'+str(R2_RnS), # mode='line', # marker=dict( # size=5, # color='rgba(0,0,0,0.0)'), # line=dict( # width=3, # color='rgba(0,0,0,0.0)') # ============================================================================= ) ] return sgf, pltData def Seg2poly(self, fileName, SGwd_length=11, SGpolyOrd=5, min_r2=0.99, polyIndex=5, window_size_percent=0.05, min_interval_percent=0.0, isplot=False): startPt = 0 endPt = 0 delta = 0 timer = 0 t = [] v = [] sgf, pltData = self.getRnSData(fileName, SGwd_length, SGpolyOrd) data, times = fT.readCSV(fileName) for i in range(len(data)): t.append(i) v.append(float(data[i])) tStart = time.time() #計時開始 #plt.plot(t,v,'-') #plt.plot(t,sgf,'-') if (len(data) > 100): pass else: window_size_percent = 1 #print('wdSize:',window_size_percent) interval = int(len(t) * window_size_percent) - 1 start = [] end = [] #intervalAry=[] coef_ary = [] coeff_5 = [] coeff_4 = [] coeff_3 = [] coeff_2 = [] coeff_1 = [] coeff_0 = [] decompData = [] #first_inl=0 R2_PnS = [] R2_PnR = [] Dlta = [] Maxr2SGF = 0.0 Maxr2RW = 0.0 MaxEnd = 0 MaxCoeff = [] MaxYs = [] rsqSGF = 0 rsqRW = 0 ys_line = [] DeltaCnt = 0 #===condition==== #max_slope=2 # 反應差 min_time_interval = int(len(t) * min_interval_percent) c = 1 while (startPt < (len(t))): #MaxStart=0 islimit = False # ============================================================================= # # if ((interval-startPt)<=min_time_interval) : # interval=interval+int((len(t)/10)) # # ============================================================================= for i in range(interval, startPt - 1, -1): if ((i - startPt) > min_time_interval): endPt = i + 1 delta = endPt - startPt coeff, ys_line, rsqSGF, rsqRW = mthT.polyLine( startPt, endPt, polyIndex, t, sgf, data) if (rsqRW >= Maxr2SGF): Maxr2SGF = rsqRW MaxYs = ys_line Maxr2RW = rsqRW #MaxStart=startPt MaxEnd = endPt MaxCoeff = coeff break elif ((i - startPt) <= min_time_interval + 1): if (Maxr2SGF == 0): endPt = len(t) delta = endPt - startPt coeff, ys_line, rsqSGF, rsqRW = mthT.polyLine( startPt, endPt, polyIndex, t, sgf, data) islimit = True else: rsqRW = Maxr2SGF endPt = MaxEnd coeff = MaxCoeff delta = endPt - startPt rsqRW = Maxr2RW ys_line = MaxYs delta = endPt - startPt islimit = True break if (rsqRW >= min_r2) or islimit: #====coeff[0] = A coeff[1] = B coeff[2] = C; Ax^2+Bx+C #start.append(time[startPt]) #end.append(time[endPt]) # ============================================================================= # if(rsqTT<min_r2): # print(c) # print(Maxr2SGF) # print(islimit) # print(i) # print(startPt) # ============================================================================= start.append(times[startPt]) if (endPt != len(times)): end.append(times[endPt]) #print(len(times),':',endPt) else: end.append(times[endPt - 1]) #print(len(times),':',endPt) #coef_ary.append(coeff) #print(np.poly1d(coeff)) coeff_5.append(float(coeff[0])) coeff_4.append(float(coeff[1])) coeff_3.append(float(coeff[2])) coeff_2.append(float(coeff[3])) coeff_1.append(float(coeff[4])) coeff_0.append(float(coeff[5])) coef_ary.extend(coeff) decompData.extend(ys_line) #print() Dlta.append(delta) DeltaCnt = DeltaCnt + endPt - startPt # print(len(decompData),'Delta=',DeltaCnt) pltData += [ go.Scatter( x=times[startPt: endPt], # assign x as the dataframe column 'x' y=ys_line, mode='lines', name='', #name=str(c)+'. R: '+str(rsqRW), marker=dict(size=5, color='rgba(255,0,0,1)'), line=dict(width=3, )) ] c += 1 #print(startPt,"-",endPt) R2_PnR.append(round(rsqRW, 3)) R2_PnS.append(round(rsqSGF, 3)) startPt = endPt interval = startPt + int((len(t) * window_size_percent)) - 1 # ============================================================================= if (interval >= len(t)): interval = len(t) - 1 #intervalAry.append(interval) MaxCoeff = [] MaxYs = [] Maxr2SGF = 0.0 MaxEnd = interval # ============================================================================= # break # ============================================================================= else: interval -= 1 tEnd = time.time() #計時結束 timer = tEnd - tStart #=================每一天壓縮後數據================================== #==each day polynorimal data dtPolyData = { 'start': start, 'end': end, 'Delta': Dlta, 'coeff_5': coeff_5, 'coeff_4': coeff_4, 'coeff_3': coeff_3, 'coeff_2': coeff_2, 'coeff_1': coeff_1, 'coeff_0': coeff_0, 'R2_Raw': R2_PnR, } headerPD = [ 'start', 'end', 'Delta', 'coeff_5', 'coeff_4', 'coeff_3', 'coeff_2', 'coeff_1', 'coeff_0' ] #輸出沒有了r2 值 dfpolyDtlData = pd.DataFrame(dtPolyData, columns=headerPD, index=None) SnrCsvfileName = fileName + "_DetailData.csv" dfpolyDtlData.to_csv(SnrCsvfileName, mode='w', index=None) print('總結:times=', len(times), 'deCompDaya=', len(decompData)) print('Compressing Time:', timer) pltData += [ go.Scatter( x=times, # assign x as the dataframe column 'x' y=decompData, mode='lines', name='CHEB', marker=dict(size=5, color='rgba(255,0,0,0.0)')) ] pltT.PlotLy(t, window_size_percent, min_interval_percent, polyIndex, fileName, pltData, isplot) return coef_ary, decompData
from dash.dependencies import Input, Output import matplotlib.pyplot as plt import seaborn as sns #from IPython.display import display, HTML #import os import plotly.offline as py import plotly.graph_objs as go from plotly import tools from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot import cufflinks as cf """ We will display stats for Fifa2019 on Jupyter NB and dataframes """ init_notebook_mode(connected=True) cf.go_offline() # connecting jupyter fifa = pd.read_csv('srcdata/fifa2019data.csv') print('Categorical columns: ', len(fifa.select_dtypes(include=object).columns)) print('Numerical columns: ', len(fifa.select_dtypes(exclude=object).columns)) # Drop columns fifa.drop(columns=[ 'Unnamed: 0', 'ID', 'Photo', 'Flag', 'Club Logo', 'Special', 'Real Face', 'Release Clause', 'Joined', 'Contract Valid Until' ], inplace=True) fifa.isnull().sum()[fifa.isnull().sum() > -9000] #Drop players not belonging to any club fifa['Club'].fillna(value='No Club', inplace=True) # Position column values is also available as features, 20+ # For position = GK, the position features are NaN, so fill them with zero # Can do this conditionally, after transpose of the df, we will skip this exercise for now
from textblob import TextBlob from wordcloud import WordCloud, STOPWORDS import plotly.plotly as py import plotly.graph_objs as go from plotly.offline import iplot import cufflinks cufflinks.go_offline() cufflinks.set_config_file(world_readable=True, theme='pearl', offline=True
import random, requests # Cluster analysis from sklearn.cluster import KMeans # linear methods from sklearn.cluster import SpectralClustering # nearest neighbors from sklearn.datasets import make_moons from sklearn.decomposition import PCA # path collection from sklearn.metrics import pairwise_distances # for K means import plotly.offline as py # import plotly in offline mode py.init_notebook_mode(connected=True) # initialize the offline mode, with access to the internet or not. import plotly.tools as tls tls.embed('https://plot.ly/~cufflinks/8') # conda install -c conda-forge cufflinks-py # import cufflinks and make it offline import cufflinks as cf cf.go_offline() # initialize cufflinks in offline mode # First time you run plotly # import plotly # username = '******' # your.username # api_key = '••••••••••' # find it under settings # your.apikey # plotly.tools.set_credentials_file(username=username, api_key=api_key) %matplotlib inline # Data sns.set(style="ticks") # for scatterplot df = sns.load_dataset("iris") sns.pairplot(df, hue="species") ### Transformations to lower dimensional space that preserves the variance
# domain代表在这个坐标上的占比 # 各种各样的线的样式 style: https://plot.ly/python/line-charts/ # Continuous Error Bars的实现方法: # https://plot.ly/python/continuous-error-bars/ # pandas的结合,可以直接从Dataframe中画图 # https://plot.ly/ipython-notebooks/cufflinks/ # 如果不想在online上画图,那么请先调用offline模式 import cufflinks as cf cf.go_offline() # cufflinks 是我见过画stack图最好用的工具 # stack的bar画出来非常方便, stack的Area可能就不太方便了 # layout_update可能会挺方便 df.iplot(layout_update={'height': 400, 'width': 900, 'title': 'XXX'}) # 或者可以吹剪传入layout # 直接获得traces df.iplot(asFigure=True)['data'] # 返回的是一堆trace,即go.scatter的list # 需要注意的是它带了颜色. # 画 horizontal lines 和 vertical lines 的方法. # https://plot.ly/ipython-notebooks/cufflinks/#lines-and-shaded-areas
def DrawMatplot(self): cf.go_offline() pd.options.mode.chained_assignment = None TOTAL_INDEX = 'Aantal' INDEXED_SUM = 'indexed_sum' DENSITY_INDEX = 'Aantal per 100.000 inwoners' ARNHEM = 'Arnhem' DELFT = 'Delft' UTRECHT = 'Utrecht' COUNTY_NAME = DELFT count = len(self.StatsDf.index) top_10 = math.ceil(count / 2) # top_10 = count DIFFEREMCE_SINCE = 1 SUM_INDEX = 'sum' DAY_INDEX = 'day' DATA_INDEX = 'data' COLOR_INDEX = 'color' DAILY_INCREASE_INDEX = "total_increase" DAILY_INCREASE_NORMALIZED_INDEX = "total_increase_index" low_color = "SALMON" county_color = "FIREBRICK" AantalDF, total_index_county, total_value_county = getTop10AndIndex(self.StatsDf, top_10, TOTAL_INDEX, COUNTY_NAME, low_color, county_color, COLOR_INDEX) total_fig = px.bar(AantalDF, x=AantalDF.index, y=TOTAL_INDEX) total_fig = total_fig.update_traces(marker_color=AantalDF[COLOR_INDEX]) total_trace = total_fig[DATA_INDEX][0] low_color = "POWDERBLUE" county_color = "DODGERBLUE" DensityDF, density_index_county, density_value_county = getTop10AndIndex(self.StatsDf, top_10, DENSITY_INDEX, COUNTY_NAME, low_color, county_color, COLOR_INDEX) denisty_fig = px.bar(DensityDF, x=DensityDF.index, y=DENSITY_INDEX) denisty_fig = denisty_fig.update_traces(marker_color=DensityDF[COLOR_INDEX]) denisty_trace = denisty_fig[DATA_INDEX][0] DifferenceDf, earliest_date = getDifferenceFromNumerOfDaysBack(self.files, DIFFEREMCE_SINCE) low_color = "PALEGREEN" county_color = "DARKGREEN" DifferenceTotalDf, difference_total_index_county, differrence_total_county = getTop10AndIndex(DifferenceDf, top_10, TOTAL_INDEX, COUNTY_NAME, low_color, county_color, COLOR_INDEX) total_change_fig = px.bar(DifferenceTotalDf, x=DifferenceTotalDf.index, y=TOTAL_INDEX) total_change_fig = total_change_fig.update_traces(marker_color=DifferenceTotalDf[COLOR_INDEX]) total_change_trace = total_change_fig[DATA_INDEX][0] low_color = "LEMONCHIFFON" county_color = "GOLD" DifferenceDensityDf, difference_density_index_county, differrence_density_county = getTop10AndIndex(DifferenceDf, top_10, DENSITY_INDEX, COUNTY_NAME, low_color, county_color, COLOR_INDEX) density_change_fig = px.bar(DifferenceDensityDf, x=DifferenceDensityDf.index, y=DENSITY_INDEX) density_change_fig = density_change_fig.update_traces(marker_color=DifferenceDensityDf[COLOR_INDEX]) density_change_trace = density_change_fig[DATA_INDEX][0] printInfo("Total", COUNTY_NAME, total_value_county, total_index_county, count) printInfo("Density", COUNTY_NAME, density_value_county, density_index_county, count) printInfo("Difference Total", COUNTY_NAME, differrence_total_county, difference_total_index_county, count) printInfo("Difference Density", COUNTY_NAME, differrence_density_county, difference_density_index_county, count) TOTAL_CASES = self.StatsDf[TOTAL_INDEX].sum() print("Total Cases: " + str(TOTAL_CASES)) county_change_df = getChangeOverTime(COUNTY_NAME, self.files) county_change_index = TOTAL_INDEX county_change_fig = px.bar(county_change_df, x=DAY_INDEX, y=county_change_index) county_change_fig = county_change_fig.update_traces(marker_color="REBECCAPURPLE") county_change_trace = county_change_fig[DATA_INDEX][0] total_change_indexed_df = normalizeOnKey(county_change_df, INDEXED_SUM, SUM_INDEX) total_change_indexed_fig = px.bar(total_change_indexed_df, x=DAY_INDEX, y=SUM_INDEX, hover_data=[INDEXED_SUM]) total_change_indexed_fig = total_change_indexed_fig.update_traces(marker_color="DARKORANGE") total_change_indexed_trace = total_change_indexed_fig[DATA_INDEX][0] daily_increase_fig = px.line(total_change_indexed_df, x=DAY_INDEX, y=DAILY_INCREASE_INDEX, hover_data=[DAILY_INCREASE_NORMALIZED_INDEX], line_shape='spline') daily_increase_fig = daily_increase_fig.update_traces(line=dict(color="CHOCOLATE")) daily_increase_fig_trace = daily_increase_fig[DATA_INDEX][0] date_string = getStringOfDate(earliest_date) sub_plot_titles = ["Total", "Density", "Total Change since: " + date_string, "Density Change since: " + date_string, "Total Cases in " + COUNTY_NAME, "Total Cases Indexed"] fig = make_subplots(rows=3, cols=2, subplot_titles=sub_plot_titles, specs=[[{"secondary_y": False}, {"secondary_y": False}], [{"secondary_y": False}, {"secondary_y": False}], [{"secondary_y": False}, {"secondary_y": True}]]) fig.add_trace(total_trace, row=1, col=1) fig.add_trace(denisty_trace, row=1, col=2) fig.add_trace(total_change_trace, row=2, col=1) fig.add_trace(density_change_trace, row=2, col=2) fig.add_trace(county_change_trace, row=3, col=1) fig.add_trace(total_change_indexed_trace, row=3, col=2, secondary_y=False) fig.add_trace(daily_increase_fig_trace, row=3, col=2, secondary_y=True) fig.update_layout(title_text="Total Cases: " + str(TOTAL_CASES)) fig.show() plt.tight_layout()
from sklearn.model_selection import train_test_split from sklearn import metrics from sklearn.metrics import classification_report from sklearn.preprocessing import StandardScaler from sklearn.metrics import accuracy_score from sklearn.neighbors import KNeighborsClassifier from sklearn.preprocessing import LabelEncoder import plotly import plotly.express as px import plotly.offline as pyo import cufflinks as cf from plotly.offline import init_notebook_mode, plot, iplot import matplotlib.pyplot as plt get_ipython().run_line_magic('matplotlib', 'inline') pyo.init_notebook_mode(connected=True) cf.go_offline() # bind pandas and plotly together # #### Function for Geodesic Distance # In[68]: def haversine(coord1, coord2): ## Geodesic distance from 2 coordinates, used when we deal with oblate spheroid to be exact ## haversine formula is used to calculate this R = 6372800 # Earth radius in meters lat1, lon1 = coord1 lat2, lon2 = coord2
import pandas as pd import logging import cufflinks as cf import plotly import plotly.offline as py import plotly.graph_objs as go import plotly.express as px cf.go_offline() # required to use plotly offline (no account required). py.init_notebook_mode() # graphs charts inline (IPython). logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) def plot_choice(year, choice1, choice2, player): ''' plot 2D figure for chosen attributes Inputs - choice1: Selected attribute to compare 1 choice2: Selected attribute to compare 2 input type: str,str Output- 2D plot based on the selected input choices ''' assert isinstance(choice1,str) and isinstance(choice2,str) assert choice1 != choice2, "please choose 2 different attributes" proc_stats_df = pd.read_csv('seasons_stats_procecced.csv', index_col=0)
import os import numpy as np import json import requests import pandas as pd from geopy.distance import geodesic import matplotlib.pyplot as plt import chart_studio.plotly as py import plotly.graph_objs as go from plotly.offline import iplot, init_notebook_mode import cufflinks cufflinks.go_offline(connected=False) init_notebook_mode(connected=False) def main(): pass def find_postal(lst, filename): for index,add in enumerate(lst): url= "https://developers.onemap.sg/commonapi/search?returnGeom=Y&getAddrDetails=Y&pageNum=1&searchVal="+add print(index,url) response = requests.get(url) data = json.loads(response.text) temp_df = pd.DataFrame.from_dict(data["results"]) temp_df["address"] = add if index == 0: file = temp_df else:
def plot_model(model, plot = '2d'): """ This function takes a model dataframe returned by create_model() function. '2d' and '3d' plots are available. Example ------- >>> rule1 = create_model(metric='confidence', threshold=0.7, min_support=0.05) >>> plot_model(rule1, plot='2d') >>> plot_model(rule1, plot='3d') Parameters ---------- model : pandas.DataFrame, default = none pandas.DataFrame returned by trained model using create_model(). plot : string, default = '2d' Enter abbreviation of type of plot. The current list of plots supported are (Name - Abbreviated String): * Support, Confidence and Lift (2d) - '2d' * Support, Confidence and Lift (3d) - '3d' Returns ------- Visual_Plot Prints the visual plot. """ #loading libraries import numpy as np import pandas as pd import plotly.express as px from IPython.display import display, HTML, clear_output, update_display #import cufflinks import cufflinks as cf cf.go_offline() cf.set_config_file(offline=False, world_readable=True) #copy dataframe data_ = model.copy() antecedents = [] for i in data_['antecedents']: i = str(i) a = i.split(sep="'") a = a[1] antecedents.append(a) data_['antecedents'] = antecedents antecedents_short = [] for i in antecedents: a = i[:10] antecedents_short.append(a) data_['antecedents_short'] = antecedents_short consequents = [] for i in data_['consequents']: i = str(i) a = i.split(sep="'") a = a[1] consequents.append(a) data_['consequents'] = consequents if plot == '2d': fig = px.scatter(data_, x="support", y="confidence", text="antecedents_short", log_x=True, size_max=600, color='lift', hover_data = ['antecedents', 'consequents'], opacity=0.5, ) fig.update_traces(textposition='top center') fig.update_layout(plot_bgcolor='rgb(240,240,240)') fig.update_layout( height=800, title_text='2D Plot of Support, Confidence and Lift' ) fig.show() if plot == '3d': fig = px.scatter_3d(data_, x='support', y='confidence', z='lift', color='antecedent support', title='3d Plot for Rule Mining', opacity=0.7, width=900, height=800, hover_data = ['antecedents', 'consequents' ]) fig.show()
import numpy as np import pandas as pd import chart_studio.plotly as py import cufflinks as cf cf.go_offline(connected=True) rand1 = np.random.rand(5) rand2 = np.random.rand(5, 2) print(rand1) print(rand2) # make df by numpy array df = pd.DataFrame(np.random.rand(10, 2), columns=["A", "B"]) print(df) # all kinds of graphs => if you want to check manual in detail, utilize this help function # print(cf.help()) # print(cf.help("bar")) df.iplot(kind="bar")
def plot_model( model, plot="2d", scale=1, ): """ This function takes a model dataframe returned by create_model() function. '2d' and '3d' plots are available. Example ------- >>> from pycaret.datasets import get_data >>> france = get_data('france') >>> from pycaret.arules import * >>> rule1 = create_model(metric='confidence', threshold=0.7, min_support=0.05) >>> plot_model(rule1, plot='2d') model: pandas.DataFrame, default = none pandas.DataFrame returned by trained model using create_model(). plot: str, default = '2d' Enter abbreviation of type of plot. The current list of plots supported are (Name - Abbreviated String): * Support, Confidence and Lift (2d) - '2d' * Support, Confidence and Lift (3d) - '3d' scale: float, default = 1 The resolution scale of the figure. Returns: None """ # loading libraries import numpy as np import pandas as pd import plotly.express as px from IPython.display import display, HTML, clear_output, update_display # import cufflinks import cufflinks as cf cf.go_offline() cf.set_config_file(offline=False, world_readable=True) # copy dataframe data_ = model.copy() antecedents = [] for i in data_["antecedents"]: i = str(i) a = i.split(sep="'") a = a[1] antecedents.append(a) data_["antecedents"] = antecedents antecedents_short = [] for i in antecedents: a = i[:10] antecedents_short.append(a) data_["antecedents_short"] = antecedents_short consequents = [] for i in data_["consequents"]: i = str(i) a = i.split(sep="'") a = a[1] consequents.append(a) data_["consequents"] = consequents if plot == "2d": fig = px.scatter( data_, x="support", y="confidence", text="antecedents_short", log_x=True, size_max=600, color="lift", hover_data=["antecedents", "consequents"], opacity=0.5, ) fig.update_traces(textposition="top center") fig.update_layout(plot_bgcolor="rgb(240,240,240)") fig.update_layout( height=800 * scale, title_text="2D Plot of Support, Confidence and Lift" ) fig.show() if plot == "3d": fig = px.scatter_3d( data_, x="support", y="confidence", z="lift", color="antecedent support", title="3d Plot for Rule Mining", opacity=0.7, width=900 * scale, height=800 * scale, hover_data=["antecedents", "consequents"], ) fig.show()
def nb_setup_plotly_cufflinks(): from plotly.offline import download_plotlyjs, init_notebook_mode import cufflinks download_plotlyjs("https://cdn.plot.ly/plotly-latest.min.js") init_notebook_mode() cufflinks.go_offline()
def get_justas_plot(history): # try: import plotly.plotly as py from plotly.offline import download_plotlyjs, init_notebook_mode, plot #, iplot import plotly.graph_objs as go import cufflinks as cf cf.go_offline() gr = [v for v in history.genealogy_history.values()] gr = [g for g in gr if type(g.dtc) is not type(None)] gr = [g for g in gr if type(g.dtc.scores) is not type(None)] keys = list(gr[0].dtc.attrs.keys()) xx = np.array([p.dtc.attrs[str(keys[0])] for p in gr]) yy = np.array([p.dtc.attrs[str(keys[1])] for p in gr]) zz = np.array([p.dtc.attrs[str(keys[2])] for p in gr]) ee = np.array([np.sum(list(p.dtc.scores.values())) for p in gr]) #pdb.set_trace() # z_data = np.array((xx,yy,zz,ee)) list_of_dicts = [] for x, y, z, e in zip(list(xx), list(yy), list(zz), list(ee)): list_of_dicts.append({ keys[0]: x, keys[1]: y, keys[2]: z, str('error'): e }) z_data = pd.DataFrame(list_of_dicts) data = [go.Surface(z=z_data.as_matrix())] layout = go.Layout( width=1000, height=1000, autosize=False, title='Sciunit Errors', scene=dict( xaxis=dict( title=str(keys[0]), #gridcolor='rgb(255, 255, 255)', #zerolinecolor='rgb(255, 255, 255)', #showbackground=True, #backgroundcolor='rgb(230, 230,230)' ), yaxis=dict( title=str(keys[1]), #gridcolor='rgb(255, 255, 255)', #zerolinecolor='rgb(255, 255, 255)', #showbackground=True, #backgroundcolor='rgb(230, 230,230)' ), zaxis=dict( title=str(keys[2]), #gridcolor='rgb(255, 255, 255)', #zerolinecolor='rgb(255, 255, 255)', #showbackground=True, #backgroundcolor='rgb(230, 230,230)' ), aspectratio=dict(x=1, y=1, z=0.7), aspectmode='manual'), margin=dict(l=65, r=50, b=65, t=90)) fig = go.Figure( data=data, layout=layout ) #,xTitle=str(keys[0]),yTitle=str(keys[1]),title='SciUnitOptimization') plot(fig, filename='sciunit-score-3d-surface.html')
# Standard plotly imports import plotly.plotly as py import plotly.graph_objs as go from plotly.offline import iplot, init_notebook_mode # Using plotly + cufflinks in offline mode import cufflinks cufflinks.go_offline(connected=True) init_notebook_mode(connected=True) df['claps'].iplot(kind='hist', xTitle='claps', yTitle='count', title='Claps Distribution') df[['time_started', 'time_published']].iplot( kind='hist', histnorm='percent', barmode='overlay', xTitle='Time of Day', yTitle='(%) of Articles', title='Time Started and Time Published')
import pandas as pd import numpy as np import statsmodels.api as sm import plotly.plotly as py import plotly.graph_objs as go from plotly.graph_objs import * from plotly.offline import * #offline version to import download_plotlyjs, init_notebook_mode, plot, iplot import cufflinks cufflinks.go_offline() #to use cufflinks offline #https://plot.ly/ipython-notebooks/cufflinks/ import seaborn as sns %matplotlib inline import matplotlib.pyplot as plt plt.style.use('seaborn-white') #for jupyter dark, change style init_notebook_mode() #to connect jupyter with javascript as plotly is interactive %config InlineBackend.figure_format = 'svg' #Graphics in SVG format are more sharp and legible import scipy.sparse import warnings import pycountry import random from pandas.tools.plotting import scatter_matrix from sklearn import model_selection from sklearn.linear_model import LogisticRegression from sklearn.linear_model import LogisticRegressionCV from sklearn.tree import DecisionTreeClassifier from sklearn.neighbors import KNeighborsClassifier from sklearn.ensemble import RandomForestClassifier from sklearn.datasets import make_classification from sklearn.discriminant_analysis import LinearDiscriminantAnalysis from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis from sklearn.naive_bayes import GaussianNB