plotly

Plotly.py: fill between lines, different color por positive/negative

为君一笑 提交于 2019-12-23 04:38:14
问题 With Plotly, I can easily plot two lines and fill the area between them: import plotly.graph_objects as go fig = go.Figure() fig.add_trace(go.Scatter( x=[1, 2, 3, 4], y=[-1, -.2, 1, 2], fill=None, mode='lines', )) fig.add_trace(go.Scatter( x=[1, 2, 3, 4], y=[-1, -.5, 0.2, .5], fill='tonexty', mode='lines', )) fig.update_layout(title_text='hello world') fig.show() How can I make it to separate the filled area in two? In particular, filling with red where y < 0 and with green where y > 0 .

Plotting a circle in leaflet using .add_artist()

半世苍凉 提交于 2019-12-23 04:00:23
问题 Starting from here and the first example from here, I'm trying to use pyplot and mplleaflet to plot a fixed-size circle on a map. (By "fixed-size", I mean that this circle is not a marker, it shouldn't adapt to the zoom level, but should stay of, say, 25m diameter whatever the zoom level). Here is what I got : import mplleaflet import matplotlib.pyplot as plt import matplotlib as mpl fig, ax = plt.subplots() x = 2.363561 y = 48.951918 r = 20 circle1 = mpl.patches.Circle((x,y), radius=r)

How to apply plotly.js to an existing svg group <g> as target instead of applying it to a target <div> element?

谁说胖子不能爱 提交于 2019-12-23 03:49:07
问题 If there is a target div in my DOM, e.g. <div id="graph"></div> I can use plotly to create a plot in that div (a full example is below): Plotly.newPlot('graph', data, layout); This will create a nested structure in the div that contains an svg element. Tn that svg element there is a contour plot, represented by some elements (see DOM structure below). That works fine. However, I have an already existing svg element (created with d3.js) and I would like to include a contour plot from plotly in

R: Plotly and subplot(): fastest way to create a subplot based on a factor

我只是一个虾纸丫 提交于 2019-12-23 03:43:13
问题 I have a dataframe such as: line station var 1 a 39446 1 b 82964 1 c 57840 1 d 78946 1 e 69972 1 f 14303 1 g 78179 2 a 37738 2 b 62261 2 c 19378 2 d 76435 2 e 17181 2 f 75148 2 g 10882 I would like to use plot_ly to create a subplot from these data. I want a barplot with station as x-values, and var as y-values. I want to have two subplots based on line. I know that I could just do: p1 <- plot_ly(data = df[df$line == "1", ], x = ~station, y = ~var, type = "bar") p2 <- plot_ly(data = df[df

Custom discrete color scale in plotly

∥☆過路亽.° 提交于 2019-12-23 03:32:34
问题 I would like to customize the colors in a plotly plot. This works fine for continuous variables and scales as per the docs: library(plotly) plot_ly(iris, x = Petal.Length, y = Petal.Width, color = Sepal.Length, colors = c("#132B43", "#56B1F7"), mode = "markers") If I make the argument to color discrete (character or factor), however, this still works but throws a warning: > plot_ly(iris, x = Petal.Length, y = Petal.Width, color = Sepal.Length>6, colors = c("#132B43", "#56B1F7"), mode =

How can I remove the size line in the hoverinfo of a Plotly chart in R?

偶尔善良 提交于 2019-12-23 03:27:16
问题 I've found the following page instructing how to create custom hover text for plotly charts in R. https://plot.ly/r/text-and-annotations/#custom-hover-text This seems to do exactly what I want, however when I copy the code (see below) into RStudio and run it locally I get an extra line in in my hoverinfo, showing the size variable. Screenshot of the chart in RStudio: How can I remove this "wt (size): 1.835" line in hoverinfo? library(plotly) p <- mtcars %>% plot_ly(x = disp, y = mpg, mode =

Coloring the axis tick text by multiple colors

↘锁芯ラ 提交于 2019-12-23 02:30:50
问题 I'm trying to plot a heatmap using R 's plotly package, where I'd like to have specific colors to specific labels of the y-axis tick text. Here's an example dataset: set.seed(1) df <- reshape2::melt(matrix(rnorm(100),10,10,dimnames = list(paste0("G",1:10),paste0("S",1:10)))) And here's what I'm trying: library(plotly) library(dplyr) plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4))

Same color assigned to same level of factor in R plotly

时光怂恿深爱的人放手 提交于 2019-12-23 02:02:57
问题 I have a Shiny app with several plotly visualisations. The user is allowed to choose several products and I would like each product to have the same unique color throughout the entire app. One of my visualisations could e.g. look like this: plot_ly(df, x = variable, y=value, type = "bar", color = Product, hoverinfo = "text", colors = colpal, text = paste0(df$value,"%")) %>% layout(xaxis=ax, yaxis=yx, legend=list(x=1, y = 0.5)) Is it possible to make sure that the first level of Product ALWAYS

Download data from plotly graph via custom modebar button, coded in R

放肆的年华 提交于 2019-12-23 01:35:21
问题 I have a plotly graph (in my case made in R / rmarkdown), and would like to download the data. Option 1 is a download button outside the graph to a data object (e.g CSV, or a table). For example Download output file csv, or this. It works, but not that neat - using custom modebar would be neater. Options 2 and 3 use a custom modebar button. plotly book - custom modebar button has a nice example with code to make the custom button. Option 2, is a download button (e.g. to csv) as a plotly

Python - plotly assigning scatterplot colors by label

谁说胖子不能爱 提交于 2019-12-22 22:48:31
问题 I'm trying to replicate one of the basic examples in Plotly R https://plot.ly/r/line-and-scatter/#qualitative-colorscales into Plotly Python. But finding it impossible. The same problem is also solved in R here: Plotly assigning colors based on label ``` trace0 = go.Scatter( x = x1, y = y1, mode = 'markers', name = ytitle + ' X vs ' + Atitle, marker=dict(size=4, symbol='circle', color=colorsIdx, colorbar= go.ColorBar(title= 'colorbar'), colorscale='Viridis') ) ``` The closest I've gotten is