plotly

python save plotly plot to local file and insert into html

喜欢而已 提交于 2019-11-29 19:22:49
I am using python and plotly to product interactive html report. This post gives a nice framework. If I produce the plot(via plotly) online, and insert the url into the html file, it works but refreshing the charts takes a long time. I wonder if I could produce the chart offline and have it embedded in the html report, so that loading speed is not a problem. I find plot offline would generate a html for the chart, but I don't know how to embed it in another html. Anyone could help? Option 1 : Use plotly's offline functionality in your Jupyter Notebook (I suppose you are using a Jupyter

add secondary description in axis values, plotly

∥☆過路亽.° 提交于 2019-11-29 18:09:05
I am using a dataframe which includes the following columns: Country, GNI, CarSalesPerCap . I am using kmeans to create clusters. In the algorithm i pass the dataframe with the two numeric columns: 'GNI', 'CarSalesPerCap' . Then i am using plotly to create a scatter plot, where x-axis is the CarsalesPerCap and Y-axis is GNI . My question is, how am i going to add to the plot the corresponding country for each point plotted on the graph. df = pd.read_sql_query(query,conn) df = df.dropna() #Cluster the data kmeans = KMeans(n_clusters=6, random_state=0).fit(df1) labels = kmeans.labels_ #Glue back

How to plot pie charts as subplots with custom size with Plotly in Python

元气小坏坏 提交于 2019-11-29 17:42:20
问题 I've been trying to make a grid of subplots with custom size with Plotly(version 1.12.9) in Jupyter notebook(offline). There is nice examples in the Plotly website but all of them are with scattered plots. I modified one of them to make it look like the one I want to and it works with scatter plots: import plotly import plotly.offline as py import plotly.graph_objs as go py.init_notebook_mode(connected=True) labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen'] values = [4500,2500,1053

Plotly update data

你说的曾经没有我的故事 提交于 2019-11-29 16:46:29
问题 Okay so i have the following code: var element = document.getElementById(scope.changeid); function getData(division,redraw) { var employeeData = []; if (!division) { $http.get(api.getUrl('competenceUserAverageByMyDivisions', null)).success(function (response) { processData(response,redraw); }); } else { $http.get(api.getUrl('competenceUserAverageByDivision', division)).success(function (response) { processData(response,redraw); }) } } function processData(data,redraw) { var y = [], x1 = [],

Direct labels and hover info to be different in plotly

落爺英雄遲暮 提交于 2019-11-29 16:30:56
I have a stacked bar chart. On the segments in the bar chart I want to add the numbers (y values) and on hover I want some different information to be shown (not name or x or y values). Is it possible? From what I can see hoverinfo let's you only duplicate the values in text or add the name. import plotly from plotly.graph_objs import Layout, Bar hoverinformation = ["test", "test2", "test3", "test4"] # this info I would like it on hover data = [] for index, item in enumerate(range(1,5)): data.append( Bar( x="da", y=[item], name="Some name", # needs to be different than the hover info text=item

Using 2+ legends from R to plotly / plot.ly

筅森魡賤 提交于 2019-11-29 15:56:53
I am using R's ggplot to create a static plot and pass that on to plot.ly to create an interactive plot. My aim to project a categorical variable to the color and a numeric variable to size. With R's [iris] data that works perfect - Like that: testplot <- ggplot(iris, aes(Sepal.Length, Sepal.Width, color=Species, size=Petal.Length)) + geom_point() py$ggplotly(testplot) https://plot.ly/~SyTpp/11/sepalwidth-vs-sepallength/ Now, I have my own dataset, a, ... > a Country OR_Edu OR_Illn total num Peru 1.75 1.67 25367 10 Philippines 1.33 0.43 33543 1 Rwanda 0.29 4.00 6443 2 Senegal 5.00 1.60 32743 3

R Plotly: Cannot re-arrange x-axis when axis type is category

旧巷老猫 提交于 2019-11-29 15:13:41
I have the following data: myData <- data.frame(FISCAL_YEAR_WEEK = c('2016-09','2016-09','2016-09','2016-09','2016-09','2016-10','2016-10','2016-10','2016-10','2016-10','2016-10','2016-10','2016-10','2016-11','2016-11','2016-11','2016-11','2016-12','2016-12','2016-12','2016-12','2016-12','2016-12','2016-14','2016-14','2016-14','2016-14'), MOTOR_VEND_ID = c('7','E','F','F','M','7','9','E','E','F','F','M','R','7','E','F','F','E','E','F','F','M','M','7','E','F','M'),HGA_SUPPLIER=c('RHO','RHO','HWY','RHO','RHO','RHO','RHO','HWY','RHO','HWY','RHO','RHO','RHO','RHO','RHO','HWY','RHO','HWY','RHO',

Removing plotly click event data

烈酒焚心 提交于 2019-11-29 13:54:49
I am designing a Shiny app which contains a plotly scatter plot. I would like for the user to be able to click on the graph to record an event using the event_data function, but then be able to clear that event on the click of an actionButton . Some example code can be seen below: library(shiny) library(plotly) ui <- fluidPage( actionButton("clearEvent", label = "clear event"), verbatimTextOutput("plotVal"), plotlyOutput('plot1') ) server <- function(input, output, session) { output$plot1 <- renderPlotly({ d <- diamonds[sample(nrow(diamonds), 1000), ] plot_ly(d, x = ~carat, y = ~price, color =

Interactive `ggplotly` graph is not plotted from inside `for` loop in `Rmd` file in R

帅比萌擦擦* 提交于 2019-11-29 12:41:59
问题 I tried to plot series of interactive ggplotly graphs from inside for loop in R markdown ( .Rmd ) file. Contents of my .Rmd file: --- title: "Untitled" output: html_document --- ```{r} library(ggplot2) # for plots library(plotly) # for interactive plots # Convert 4 variables to factor variables: factor_vars <- c("vs", "am", "gear", "carb") mtcars[factor_vars] <- data.frame(Map(as.factor, mtcars[factor_vars])) for (VAR in factor_vars) { cat(paste("Factor variable:", VAR)) # Contents of "VAR"

Plotly R: Cant get points to plot when two values present per x factor level

你离开我真会死。 提交于 2019-11-29 12:38:14
I have a data frame like this: dput(df) structure(list(x = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), .Label = c("41197708", "41223094", "41244000", "41244435", "41244936"), class = "factor"), y = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2)), .Names = c("x", "y"), row.names = c(NA, -10L), class = "data.frame") Trying to print a scatter plot with points as follows: plot_ly(df, x = levels(x), y = y, mode = 'markers') I only see points corresponding to y = 1 and not y = 2. Any idea why? The following works in plotly, but then it treats x axis values as numeric / continuous (not what I want): plot