plotly

Plotly: How to give different label names in a dropdown menu?

邮差的信 提交于 2021-02-07 20:06:11
问题 I was learning plotly dropdown menu and stumbled on a label problem. Question How to show labels sin and sin-1 when selected Sine. And show labels tan and tan-1 when selected Tan? MWE # imports import plotly.graph_objects as go import numpy as np # data x = np.linspace(-np.pi, np.pi, 100) y1 = np.sin(x) y1b = y1-1 y2 = np.tan(x) y2b = y2-1 # plotly setup fig = go.Figure() # Add one ore more traces fig.add_traces(go.Scatter(x=x, y=y1,name='sin')) fig.add_traces(go.Scatter(x=x, y=y1b,name='sin

plotly have trace without data in legend

独自空忆成欢 提交于 2021-02-07 19:14:30
问题 As a follow on to a previous question Suppose I want to show a set of bars, where each bar could be one of the choices: A, B, or C, each which has a different color. I would like to show the bars, but also if none the bars fall into a particular category still have that category show up in the legend. Unfortunately the categories without colors seem to get dropped. Notice in this example how the category labeled 'C' which should be blue is dropped from the legend: data = [ { x: [1, 3, 4], y:

ggplotly and multiple highlight functions

时光总嘲笑我的痴心妄想 提交于 2021-02-07 10:31:15
问题 How can I use two or more highlight functions on a ggplotly object. In the following example I want to highlight the hovered bar in black the clicked bar in blue When using 2 highlight functions, only the last one is used and it obviously overwrites the previous one. So how can I define different behaviour for click and hover-events? Data: dnew <- {structure(list(time_stamp = structure(c(1514761200, 1514847600, 1514934000, 1515020400, 1515106800, 1515193200, 1515279600, 1515366000, 1515452400

ggplotly and multiple highlight functions

柔情痞子 提交于 2021-02-07 10:31:12
问题 How can I use two or more highlight functions on a ggplotly object. In the following example I want to highlight the hovered bar in black the clicked bar in blue When using 2 highlight functions, only the last one is used and it obviously overwrites the previous one. So how can I define different behaviour for click and hover-events? Data: dnew <- {structure(list(time_stamp = structure(c(1514761200, 1514847600, 1514934000, 1515020400, 1515106800, 1515193200, 1515279600, 1515366000, 1515452400

change the value in tooltips in plotly

限于喜欢 提交于 2021-02-07 10:22:25
问题 library(ggplot2) library(plotly) dataset = data.frame(x = c(1,10, 100, 1000), y = c(1000, 100, 10, 1)) p = ggplot(data = dataset, aes(x = x, y = y)) + geom_point() + geom_line() + scale_x_log10() + scale_y_log10() ggplotly(p) With above codes, you can have a plotly graph with tooltip. The x and y axis show the original data. But the values in tooltip is shown as (0,3), (1,2), (2,2), (3,0). What I want in the tooltip is (1, 1000), (10, 100), (100, 10), (1000, 1). Is there any way to do it? 回答1

change the value in tooltips in plotly

爷,独闯天下 提交于 2021-02-07 10:21:32
问题 library(ggplot2) library(plotly) dataset = data.frame(x = c(1,10, 100, 1000), y = c(1000, 100, 10, 1)) p = ggplot(data = dataset, aes(x = x, y = y)) + geom_point() + geom_line() + scale_x_log10() + scale_y_log10() ggplotly(p) With above codes, you can have a plotly graph with tooltip. The x and y axis show the original data. But the values in tooltip is shown as (0,3), (1,2), (2,2), (3,0). What I want in the tooltip is (1, 1000), (10, 100), (100, 10), (1000, 1). Is there any way to do it? 回答1

How do I suppress warnings with plotly?

余生长醉 提交于 2021-02-07 10:12:26
问题 I'd like to stop warnings in plotly without turning off warnings globally This code is going into a function so it could be run in a different session This is my code fit <- plot_ly(credit_old, y = ~score, color = ~fte, type = "box") suppressWarnings(fit) I still get Warning messages: 1: In RColorBrewer::brewer.pal(N, "Set2") : minimal value for n is 3, returning requested palette with 3 different levels 2: In RColorBrewer::brewer.pal(N, "Set2") : minimal value for n is 3, returning requested

How do I suppress warnings with plotly?

半城伤御伤魂 提交于 2021-02-07 10:12:18
问题 I'd like to stop warnings in plotly without turning off warnings globally This code is going into a function so it could be run in a different session This is my code fit <- plot_ly(credit_old, y = ~score, color = ~fte, type = "box") suppressWarnings(fit) I still get Warning messages: 1: In RColorBrewer::brewer.pal(N, "Set2") : minimal value for n is 3, returning requested palette with 3 different levels 2: In RColorBrewer::brewer.pal(N, "Set2") : minimal value for n is 3, returning requested

Plotly: How to save plotly express plot into a html or static image file?

£可爱£侵袭症+ 提交于 2021-02-07 09:02:33
问题 I love plotly and recently plotly.express. However, I feel saving the figure is pretty tricky. How to save plotly.express or plotly plot into a individual html or static image file? Anyone can help? Thanks 回答1: Updated answer: With newer versions of plotly, static Image pxport in Python is a breeze. Just make sure to install kaleido using: pip install -U kaleido or, for Anaconda: conda install -c conda-forge python-kaleido And then run fig.write_image("<filename>") and `.pdf` are all

How to set different text and hoverinfo text

*爱你&永不变心* 提交于 2021-02-07 06:19:04
问题 I am working with the plotly package, and I cannot find a way to display different things on the chart itself and in the hoverinfo. Here is an example of a barchart: library(plotly) library(dplyr) data(iris) df <- iris %>% group_by(Species) %>% summarise(n = n(), avg = mean(Sepal.Length)) p1 <- plot_ly(data = df, x = ~Species, y = ~n, type = "bar", text = ~paste("Species :", Species, "<br> Avg :", avg), textposition = "auto", hoverinfo = "text") From this code I get this: And I would like to