plotly

Plotly bar chart - change color based on positive/negative value - python

感情迁移 提交于 2020-08-05 13:17:39
问题 I have the following code which plots a bar chart (1 series), but I need the bars to be coloured blue if the 'Net' value is positive, and red if its negative: import pandas as pd import plotly.graph_objects as go df = pd.DataFrame({ 'Net':[15,20,-10,-15], 'Date':['07/14/2020','07/15/2020','07/16/2020','07/17/2020'] }) df['Date'] = pd.to_datetime(df['Date']) fig = go.Figure(data=[go.Bar(name='Net', x=df['Date'], y=df['Net'])]) fig.update_layout(barmode='stack') fig.show() 回答1: You can check

Plotly bar chart - change color based on positive/negative value - python

為{幸葍}努か 提交于 2020-08-05 13:15:51
问题 I have the following code which plots a bar chart (1 series), but I need the bars to be coloured blue if the 'Net' value is positive, and red if its negative: import pandas as pd import plotly.graph_objects as go df = pd.DataFrame({ 'Net':[15,20,-10,-15], 'Date':['07/14/2020','07/15/2020','07/16/2020','07/17/2020'] }) df['Date'] = pd.to_datetime(df['Date']) fig = go.Figure(data=[go.Bar(name='Net', x=df['Date'], y=df['Net'])]) fig.update_layout(barmode='stack') fig.show() 回答1: You can check

Plotly bar chart - change color based on positive/negative value - python

≡放荡痞女 提交于 2020-08-05 13:15:29
问题 I have the following code which plots a bar chart (1 series), but I need the bars to be coloured blue if the 'Net' value is positive, and red if its negative: import pandas as pd import plotly.graph_objects as go df = pd.DataFrame({ 'Net':[15,20,-10,-15], 'Date':['07/14/2020','07/15/2020','07/16/2020','07/17/2020'] }) df['Date'] = pd.to_datetime(df['Date']) fig = go.Figure(data=[go.Bar(name='Net', x=df['Date'], y=df['Net'])]) fig.update_layout(barmode='stack') fig.show() 回答1: You can check

Plotly bar chart - change color based on positive/negative value - python

ⅰ亾dé卋堺 提交于 2020-08-05 13:15:23
问题 I have the following code which plots a bar chart (1 series), but I need the bars to be coloured blue if the 'Net' value is positive, and red if its negative: import pandas as pd import plotly.graph_objects as go df = pd.DataFrame({ 'Net':[15,20,-10,-15], 'Date':['07/14/2020','07/15/2020','07/16/2020','07/17/2020'] }) df['Date'] = pd.to_datetime(df['Date']) fig = go.Figure(data=[go.Bar(name='Net', x=df['Date'], y=df['Net'])]) fig.update_layout(barmode='stack') fig.show() 回答1: You can check

Plotly bar chart - change color based on positive/negative value - python

て烟熏妆下的殇ゞ 提交于 2020-08-05 13:15:07
问题 I have the following code which plots a bar chart (1 series), but I need the bars to be coloured blue if the 'Net' value is positive, and red if its negative: import pandas as pd import plotly.graph_objects as go df = pd.DataFrame({ 'Net':[15,20,-10,-15], 'Date':['07/14/2020','07/15/2020','07/16/2020','07/17/2020'] }) df['Date'] = pd.to_datetime(df['Date']) fig = go.Figure(data=[go.Bar(name='Net', x=df['Date'], y=df['Net'])]) fig.update_layout(barmode='stack') fig.show() 回答1: You can check

Plotly: How to plot just month and day on x axis? (Ignore year)

你离开我真会死。 提交于 2020-08-05 07:48:15
问题 I am trying to plot timeseries data and would like the x axis to just be Month and Day. Plotly requires format to be yyyy-mm-dd , but I have daily averages from a data set over a few years, so I just want to plot mm-dd on the x axis. When I send a datetime that is just mm-dd it assumes the mm to be the year. Can I get it to bypass the year and only take mm-dd ? df_en_ave1.index = df_en_ave1.index.strftime('%m-%d') #convert my index to month and day datetime trace1=go.Scatter(x=df_en_ave1

Embedding dash plotly graphs into html

时光总嘲笑我的痴心妄想 提交于 2020-08-05 06:09:53
问题 I want to embed Plotly graph in my own html file. Using Dash, I can generate the same graph into API local server. However for my own HTML file, I did not get any solution: My Dash solution: import dash import dash_core_components as dcc import dash_html_components as html app = dash.Dash() app.layout = html.Div(children=[ html.H1(children='Dash Tutorials'), dcc.Graph( id='example', figure={ 'data': [ {'x': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 'y': [9, 6, 2, 1, 5, 4, 6, 8, 1, 3], 'type': 'bar',

Is there a simple way to plot vertical lines on scatter plots in plotly

痞子三分冷 提交于 2020-08-05 03:39:07
问题 I am trying to re-work some jupyter notebooks using plotly instead of matplotlib . My original function is def plot_power_spectrum(y): ps = np.abs(np.fft.fft(y - np.mean(y)))**2 time_step = 1.0/6 # hours freqs = np.fft.fftfreq(y.size, time_step) idx = np.argsort(freqs) plt.plot(freqs[idx], ps[idx]) plt.axvline(2*np.pi/168.0, color="magenta", alpha=0.4, lw=5) plt.axvline(-2*np.pi/168.0, color="magenta", alpha=0.4, lw=5) I can't see a simple way to add such vertical lines (or other markup) in

How can I save plotly graphs in high quality?

我的梦境 提交于 2020-08-04 05:53:13
问题 Every graph that I make in plotly looks great up until the moment I save it, so the image looks kind of matte, if it makes sense, just really bad quality. Does anyone know how to save it in high quality? You can use this basic chart as an example. library(plotly) x <- c(1:100) random_y <- rnorm(100, mean = 0) data <- data.frame(x, random_y) p <- plot_ly(data, x = ~x, y = ~random_y, type = 'scatter', mode = 'lines') Thank you! 回答1: At least in Plotly v4.7.1+ you can export the graph as SVG

Plotly: treemap element with “href” not working

隐身守侯 提交于 2020-08-03 10:35:32
问题 I have simple table whin href link inside the text. But clicking on it doesn't open the page. is there any easy way to do that? import plotly.express as px df = px.data.gapminder().query("year == 2007") link_ref = '<a xlink:href="http://google.com" style="cursor: pointer" target="_blank" rel="noopener noreferrer">{}</a>' df['country'] = df['country'].apply(lambda item: link_ref.format(item, "{}")) fig = px.treemap(df, path=[ 'continent', 'country'], values='pop', color='lifeExp', hover_data=[