plotly
Plotly: How to filter a pandas dataframe using a dropdown menu?
You can set up one trace and a button option for each individual trace. This will turn this figure… … into this: The button option A will be replaced with the first column in your dataframe. And the dropdown menu will let you choose which column to display in your figure. Code: import numpy as … Read more
Plotly chart not showing in Jupyter notebook
You need to change init_notebook_mode call and remove connected=True, if you want to work in offline mode. Such that: # Import the necessaries libraries import plotly.offline as pyo import plotly.graph_objs as go # Set notebook mode to work in offline pyo.init_notebook_mode() # Create traces trace0 = go.Scatter( x=[1, 2, 3, 4], y=[10, 15, 13, 17] … Read more
Interactive matplotlib figures in Google Colab
Below is an example of creating interactive iplot() in Plotly and cufflinks() on Google Colab Notebook. Used functions and suggestions from the answer [1, 2] The key seems to be to include configure_plotly_browser_state() in the cell that does the plotting. Code below should work: Import libraries import datetime from datetime import date import pandas as … Read more
How to display charts in Spyder
If you’d like to develop your plotly figures in Spyder, perhaps because of Spyders superb variable explorer, you can easily display a non-interactive image by just running fig.show(). Note that this is for newer versions of plotly where you don’t have to worry about iplot and plotly.offline. And if you’d like display your figure in … Read more
How to define colors in a figure using Plotly Graph Objects and Plotly Express
First, if an explanation of the broader differences between go and px is required, please take a look here and here. And if absolutely no explanations are needed, you’ll find a complete code snippet at the very end of the answer which will reveal many of the powers with colors in plotly.express Part 1: The … Read more
Plotly: How to specify colors for a group using go.Bar?
You could simply use a dictionary like this: colors = {‘A’:’steelblue’, ‘B’:’firebrick’} The only challenge lies in grouping the dataframe for each unique type and adding a new trace for each type using a for loop. The code snippet below takes care of that to produce this plot: # imports import pandas as pd import … Read more
Plotly: How to remove empty dates from x axis?
I had the same problem with my graph. Just add the following to layout code: xaxis=dict(type = “category”) Note: I have used import plotly.graph_objs as go and NOT import plotly.express as px This worked for me. Hope it helps you too.
How to make a line plot from a pandas dataframe with a long or wide format
Here you’ve tried to use a pandas dataframe of a wide format as a source for px.line. And plotly.express is designed to be used with dataframes of a long format, often referred to as tidy data (and please take a look at that. No one explains it better that Wickham). Many, particularly those injured by … Read more
Plotly legend next to each subplot, Python
The solution is to create an HTML file that merge sevral charts offline rendered as html files: import plotly import plotly.offline as py import plotly.graph_objs as go fichier_html_graphs=open(“DASHBOARD.html”,’w’) fichier_html_graphs.write(“<html><head></head><body>”+”\n”) i=0 while 1: if i<=40: i=i+1 #______________________________–Plotly–______________________________________ color1 = ‘#00bfff’ color2 = ‘#ff4000’ trace1 = go.Bar( x = [‘2017-09-25′,’2017-09-26′,’2017-09-27′,’2017-09-28′,’2017-09-29′,’2017-09-30′,’2017-10-01’], y = [25,100,20,7,38,170,200], name=”Debit”, marker=dict( color=color1 ) … Read more