def paral(selected_cluster, selected_ciudad, choose): clean = get_views.get_view_by_name('canal_edad_tipo_ciudad_cluster') df = clean[clean['ciudad_tienda'] == selected_ciudad] df10 = df['cluster_id'].unique() if selected_cluster is None: dff = get_views.get_view_by_name('paralell_plot_cluster') grupos = dff[(dff['ciudad_tienda'] == selected_ciudad)] fig2 = px.parallel_categories( grupos, dimensions=choose, color="valor_neto", color_continuous_scale=px.colors.sequential.Inferno, title='Parallel Categories Sales Category Diagram') else: if selected_cluster in list(df10): dff = get_views.get_view_by_name('paralell_plot_cluster') grupos = dff[(dff['ciudad_tienda'] == selected_ciudad) & dff['cluster_id'].isin([selected_cluster])] fig2 = px.parallel_categories( grupos, dimensions=choose, color="valor_neto", color_continuous_scale=px.colors.sequential.Inferno, title='Parallel Categories Sales Category Diagram') else: dff = get_views.get_view_by_name('paralell_plot_cluster') grupos = dff[(dff['ciudad_tienda'] == selected_ciudad)] fig2 = px.parallel_categories( grupos, dimensions=choose, color="valor_neto", color_continuous_scale=px.colors.sequential.Inferno, title='Parallel Categories Sales Category Diagram') return fig2
def test_parcats_dimensions_max(): df = px.data.tips() # default behaviour fig = px.parallel_categories(df) assert [d.label for d in fig.data[0].dimensions] == [ "sex", "smoker", "day", "time", "size", ] # explicit subset of default fig = px.parallel_categories(df, dimensions=["sex", "smoker", "day"]) assert [d.label for d in fig.data[0].dimensions] == ["sex", "smoker", "day"] # shrinking max fig = px.parallel_categories(df, dimensions_max_cardinality=4) assert [d.label for d in fig.data[0].dimensions] == [ "sex", "smoker", "day", "time", ] # explicit superset of default, violating the max fig = px.parallel_categories(df, dimensions=["sex", "smoker", "day", "size"], dimensions_max_cardinality=4) assert [d.label for d in fig.data[0].dimensions ] == ["sex", "smoker", "day", "size"]
def get_parallel_categories(dataframe, target_feature): try: fig = px.parallel_categories( dataframe, color=target_feature, color_continuous_scale=px.colors.sequential.Inferno) except: fig = px.parallel_categories(dataframe) graphJSON = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder) return graphJSON
def visualize( self, object: PipelineView, *args: Any, **kwargs: Any ) -> Figure: """Creates a pipeline lineage diagram using plotly.""" logger.warning( "This integration is not completed yet. Results might be unexpected." ) category_dict = {} dimensions = ["run"] for run in object.runs: category_dict[run.name] = {"run": run.name} for step in run.steps: category_dict[run.name].update( { step.name: str(step.id), } ) if step.name not in dimensions: dimensions.append(f"{step.name}") category_df = pd.DataFrame.from_dict(category_dict, orient="index") category_df = category_df.reset_index() fig = px.parallel_categories( category_df, dimensions, color=None, labels="status", ) fig.show() return fig
def get_cat_plot(df, columns): df = df.copy() df_1 = df[columns] df_1 = df_1.groupby(columns).size().reset_index(name='count') fig = px.parallel_categories( df_1, dimensions=columns, color="count", color_continuous_scale=px.colors.sequential.Pinkyl, ) fig.update_layout( autosize=False, margin=dict(l=150, r=100, t=40, b=40), paper_bgcolor="#ffffff", font=dict( family="Courier New", size=15, color="#7f7f7f" ), title_text='', legend_orientation="h" ) return fig
def parallel_categories(): """Parallel Categories Plot.""" sfo_avg_price_by_neighborhood = sfo_data.groupby(['year', 'neighborhood' ]).mean().reset_index() top10_neighborhoods = sfo_data.groupby(['neighborhood']).mean() top10_neighborhoods.sort_values(['sale_price_sqr_foot'], ascending=False, inplace=True) top10_neighborhoods = top10_neighborhoods.reset_index().head(10) df_expensive_neighborhoods_per_year = sfo_avg_price_by_neighborhood[ sfo_avg_price_by_neighborhood["neighborhood"].isin( top10_neighborhoods["neighborhood"])] cat_plot = px.parallel_categories( top10_neighborhoods, dimensions=[ 'neighborhood', 'sale_price_sqr_foot', 'housing_units', 'gross_rent' ], color='sale_price_sqr_foot', color_continuous_scale=px.colors.sequential.Inferno, labels={ 'neighborhood': 'neighborhood', 'sale_price_sqr_foot': 'sale_price_sqr_foot', 'housing_units': 'housing_units', 'gross_rent': 'gross_rent' }, ) return cat_plot
def plot_categorical_categorical(df, feature_1, feature_2): fig = px.parallel_categories( df, dimensions=[feature_1, feature_2], ) fig.update_layout(title="Plot of {} vs. {}".format(feature_1, feature_2)) st.plotly_chart(fig)
def update_figure(year2): newdata = data[data['ReportPeriod'].str.slice(start=6, stop=10) == ( str(year2))][[ 'ReportPeriod', 'Terminal', 'Domestic_International', 'Arrival_Departure' ]] figure = px.parallel_categories(newdata) return figure
def g5(batch_id, color, colorset): input_model = models.BatchInput(batch_id) df = input_model.as_pandas_dataframe() fig = px.parallel_categories(df, color=color, color_continuous_scale=get_colorset(colorset)) div = opy.plot(fig, auto_open=False, output_type='div') return div
def parallel_categories_plotly(*args, plotly_width=1200, plotly_height=600, **kwargs): fig = px.parallel_categories(*args, **kwargs, color_continuous_scale=color_scale) fig.update_layout(autosize=False, width=plotly_width, height=plotly_height) return fig
def parallel_categories_index(): parallel_categories_index = px.parallel_categories(data_csv, dimensions=["Name","Population Size","Income Range","Poverty Level"], color="Year", color_continuous_scale=px.colors.sequential.Blues, labels={"Name": "Borough"}, width=970) return parallel_categories_index
def get_parallel_categories(): parallel_categories = px.parallel_categories( top10_df_plot, dimensions=[ "neighborhood", "sale_price_sqr_foot", "housing_units", "gross_rent" ], color="sale_price_sqr_foot", title="Parallel Categories Plot.") return parallel_categories
def update_graph(selectedData): if selectedData: indices = [point['pointIndex'] for point in selectedData['points']] dff = df.iloc[indices, :] else: dff = df fig = px.parallel_categories(dff, dimensions=['Type_1', 'Color', 'Body_Style'], labels={'Type': 'Type_1', 'Color': 'Color', 'Body Style': 'Body_Style'} ) return fig
def updateParallelCategoriesPlot(productCategory, product, company): print("Running updateParallelCategoriesPlot callback") dff = getDataFrameFilteredBy(productCategory, product, company) dff = dff.drop_duplicates(subset=[ "Company", "Product Category", "Product", "Purchase Type", "Age" ]) fig = px.parallel_categories( dff, dimensions=["Product Category", "Product", "Purchase Type", "Age"], color="Age", color_continuous_scale=px.colors.sequential.Rainbow, title="Product, Purchase Type, and Age Information", ) return fig
def update_parralel(value): # New dataframe to make the map out of df = pd.read_csv( os.path.join('..', 'datasets', 'Police_Department_Incidents_-_Previous_Year__2016_.csv')) df['color'] = df.apply(lambda row: get_color(row), axis=1) df['Time of Day'] = df.apply(lambda row: get_time_of_day(row), axis=1) df = df[df.Category.isin(value)] fig = px.parallel_categories( df, color='color', dimensions=['DayOfWeek', 'PdDistrict', 'Time of Day']) fig.update_layout(showlegend=True) return fig
def parallel_categories(): """Parallel Categories Plot.""" # YOUR CODE HERE! avg = df.groupby([df['neighborhood']]).mean() avg2 = avg.sort_values(by='sale_price_sqr_foot', ascending=False).head(10) parallel_cat = px.parallel_categories( avg2.reset_index().round(1), dimensions=[ 'neighborhood', 'sale_price_sqr_foot', 'housing_units', 'gross_rent' ], color="sale_price_sqr_foot", color_continuous_scale=px.colors.sequential.Inferno) return parallel_cat
def parallel_categories(self, parameters, scores, score_name_to_plot='mean_test_score', message=''): parameters_local = parameters.copy() scores_local = scores[score_name_to_plot].copy() temp_df = parameters_local.join(scores_local, how='outer') temp_df = temp_df.sort_values('mean_test_score', ascending=False) fig = px.parallel_categories( temp_df, color='mean_test_score', color_continuous_scale=px.colors.sequential.Inferno) filename = os.path.join(self.current_directory, message + '_parallel_categories_plot.html') plotly.offline.plot(fig, show_link=True, filename=filename)
def para_coord(df=para_df()): fig = px.parallel_categories( df, dimensions=['freeshippingflag', 'PRODUCTGROUPNAME', 'channel'], color='log_totalprice', color_continuous_scale=px.colors.sequential.Inferno, labels={ 'PRODUCTGROUPNAME': 'Product groupname', 'freeshippingflag': 'Free shipping', 'channel': 'Campaign channel', 'log_totalprice': 'Log(TotalRevenue)' }, height=500) fig = fig.update_layout(showlegend=False, margin=dict(l=30, r=30, t=20, b=20)) return fig
def results(request, pk): reading = Reading.objects.get(pk=pk) query = str(reading.cards.all().query) df = pandas.read_sql_query(query, connection) fig_elements = px.pie(df, names='card_element', color_discrete_sequence=px.colors.sequential.RdBu) graph_elements = fig_elements.to_html(full_html=False, default_height=350, default_width=350) fig_arcana_rank = px.pie(df, names='card_arcana_rank', color_discrete_sequence=px.colors.sequential.RdBu) graph_arcana_rank = fig_arcana_rank.to_html(full_html=False, default_height=350, default_width=350) fig_categories = px.parallel_categories( df, dimensions=['card_element', 'card_astro_sign', 'card_astro_planet']) graph_categories = fig_categories.to_html(full_html=False, default_height=350, default_width=850) context = { "question": reading.question, "reading_id": reading.id, "reading_num_cards": reading.num_of_cards, "cards": reading.cards.all(), "plot_elements_div": graph_elements, "plot_arcana_rank_div": graph_arcana_rank, "plot_categories_div": graph_categories } return render(request, "results.html", context)
def generate_parallel_categories(dataset, group, filter=None, filter_value=None, year=None): df = dataset.copy() group = ['Rango de edad', 'Sexo', 'Año', 'Total'] year = 2015 filter = 'Tipo de delito' filter_value = 'Homicidio' if filter_value != None: df = df[df[filter] == filter_value] if year != None: df = df[df['Año'] == year] df = df.groupby(group).sum().reset_index() fig = px.parallel_categories(df, color="Total", color_continuous_scale='Bluered') fig.show()
def update_histogram(numeric1, numeric2, selected_data, var1, var2, var3, var4): if selected_data == None: selected_data = { "points": list(map(lambda x: {"pointNumber": x}, list(range(len(df))))) } selected_indices = list( map(lambda x: x['pointNumber'], selected_data['points'])) scatter = px.scatter(df, x=numeric1, y=numeric2) scatter.update_traces(selectedpoints=selected_indices) scatter.update_layout(dragmode='lasso') pc_df = df.iloc[selected_indices, :] parallel_categories = px.parallel_categories( pc_df, dimensions=[var1, var2, var3, var4], color="will_readmit_for_sepsis", labels={ var1: var1.split('_')[0].title(), var2: var2.split('_')[0].title(), var3: var3.split('_')[0].title(), var4: var4.split('_')[0].title(), }) parallel_categories.update_traces( dimensions=([{ "categoryorder": "array", "ticktext": ["Wasn't Diagnosed", "Was Diagnosed"] }] * 4)) return [scatter, parallel_categories]
# -*- coding: utf-8 -*- """ Created on Mon Nov 23 22:37:17 2020 @author: 54963 """ import numpy as np import pandas as pd import plotly as py import plotly.express as px import plotly.graph_objects as go import matplotlib.pyplot as plt #from plotly.offline import iplot, plot, init_notebook_mode # 加载数据 flight = pd.read_csv('Flights dataset.csv') # timesData相关信息 #flight.info() flight.head() fig = px.parallel_categories(flight) fig.show()
labels={ "species_id": "Species", "sepal_width": "Sepal Width", "sepal_length": "Sepal Length", "petal_width": "Petal Width", "petal_length": "Petal Length", }, color_continuous_scale=px.colors.diverging.Tealrose, color_continuous_midpoint=2, ) fig.write_html(os.path.join(dir_name, "parallel_coordinates.html")) import plotly.express as px tips = px.data.tips() fig = px.parallel_categories( tips, color="size", color_continuous_scale=px.colors.sequential.Inferno) fig.write_html(os.path.join(dir_name, "parallel_categories.html")) import plotly.express as px tips = px.data.tips() fig = px.scatter( tips, x="total_bill", y="tip", color="size", facet_col="sex", color_continuous_scale=px.colors.sequential.Viridis, render_mode="webgl", ) fig.write_html(os.path.join(dir_name, "scatter_webgl.html"))
def parallel_categories(): """Parallel Categories Plot.""" plelcategplot=px.parallel_categories(top,color='sale_price_sqr_foot',) return plelcategplot
# Creating Appellate results to use in visuals if requested df["Appellate"] = np.random.randint(1, 3, size=len(df)) df.loc[df['Outcome'] == 'Granted', 'Appellate'] = 'N/A' df.loc[df['Outcome'] == 'Denied', 'Appellate'] = 'N/A' df.loc[df['Appellate'] == 1, 'Appellate'] = 'Appeal Granted' df.loc[df['Appellate'] == 2, 'Appellate'] = 'Appeal Denied' number = LabelEncoder() df['Outcome_enc'] = number.fit_transform(df['Outcome']) external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] app = dash.Dash(__name__, external_stylesheets=external_stylesheets) fig = px.parallel_categories( df, dimensions=["Outcome", "Protected Ground", "Country"], color="Outcome_enc", color_continuous_scale=px.colors.sequential.Viridis) app.layout = html.Div(children=[ html.H1(children='Hello Dash'), html.Div(children=''' Dash: A web application framework for Python. '''), dcc.Graph(id='example-graph', figure=fig) ]) if __name__ == '__main__': app.run_server(debug=True)
def build_sankey(): sankey_df = df[['Type_1', 'Body_Style']] fig = px.parallel_categories(sankey_df) return fig
# Fetch the data from all expensive neighborhoods per year. df_expensive_neighborhoods_per_year = sfo_avg_price_by_neighborhood[ sfo_avg_price_by_neighborhood["neighborhood"].isin( top10_neighborhoods["neighborhood"])] df_expensive_neighborhoods_per_year.head(10) # In[189]: plot = px.parallel_categories( top10_neighborhoods, dimensions=[ 'neighborhood', 'sale_price_sqr_foot', 'housing_units', 'gross_rent' ], color='sale_price_sqr_foot', color_continuous_scale=px.colors.sequential.Inferno, labels={ 'neighborhood': 'neighborhood', 'sale_price_sqr_foot': 'sale_price_sqr_foot', 'housing_units': 'housing_units', 'gross_rent': 'gross_rent' }, width=1000, ) plot.show() # In[ ]: # In[190]: # Parallel Categories Plot px.parallel_coordinates(
app.layout = html.Div([ html.Div([ html.H1( children='Análisis Personas en Ciencia y técnica', className='twelve columns', style={ 'textAlign': 'center', }) ]), html.Div([dcc.Graph(id = "paralel", figure = px.parallel_categories(path))]), html.Div([ html.Div([ dcc.Graph( id='fig_scatter_3d', figure = fig_scatter_3d ), ], className="six columns", style = {"margin-top": "5px", "margin-bottom": "10px"} ),
], labels={ "total_enrollment": "Enrollment", "male_num": "Male", "female_num": "Female", "asian_num": "Asian", "white_num": "White", "hispanic_num": "Hispanic", "black_num": "Black" }, title="7 Axes Parallel Coordinate Display for Numerical Data")), dcc.Graph(figure=px.parallel_categories( dataset3, dimensions=['DBN', 'name', 'year'], labels={ "DBN": "District Borough Number", "name": "Name", "year": "Year" }, title="3 Axes Parallel Coordinate Display for Categorical Data")), html.Br(), dcc.Link('Go back', href='/advanced-displays') ]) pca_plot_layout = html.Div([ html.H1('PCA & Scree Plot Page', style={'text-align': 'center'}), html.Br(), dcc.Graph(figure=px.scatter( components, x=0, y=1,
) income_distribution = pd.read_csv( 'https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-02-09/income_distribution.csv' ) income_mean = pd.read_csv( 'https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-02-09/income_mean.csv' ) ####################### parallel categories plot ########################### import plotly.express as px fig = px.parallel_categories( lifetime_earn, color="lifetime_earn", color_continuous_scale=px.colors.sequential.Inferno, labels={ 'gender': 'Gender', 'race': 'Race', 'lifetime_earn': 'Lifetime Earnings (US$)' }) fig.update_layout( #autosize=False, #width=950, #height=1100, #showlegend=False, #legend_title="Legend Title", title="Average lifetime earning by race/gender", #title_text='Your title', title_x=0.5, #xaxis_title="Year", #yaxis_title="Percent of population (persons age 25 and over)",