plotly

Obtain observations in geom_hex in a single plot (Shiny)

孤街浪徒 提交于 2019-12-04 14:55:28
I am attempting to create an interactive plot of hexbins where a user can click on a given hexbin and receive a list of all observations of the original data frame that were grouped in that clicked hexbin. Below is a MWE that seems pretty close to my goal. I am using Shiny, hexbin(), and ggplotly. app.R library(shiny) library(plotly) library(data.table) library(GGally) library(reshape2) library(hexbin) ui <- fluidPage( plotlyOutput("plot"), verbatimTextOutput("click") ) server <- function(input, output, session) { #Create data set.seed(1) bindata <- data.frame(x=rnorm(100), y=rnorm(100)) h <-

ggplotly and geom_bar when using dates - latest version of plotly (4.7.0)

馋奶兔 提交于 2019-12-04 14:42:16
问题 Say you have the following df: x <- as.Date(c("1963-06-01", "1964-06-01", "1965-06-01","1966-06-01")) y <- c(1162.7, 975.4, 1280.3, 1380.0) data<- data.frame(x, y) when you plot it using ggplot, everything seems to work: ggplot(data = data, aes(x = x, y = y)) + geom_bar(stat = "identity") ggplot works However, if we add a ggplotly wrap around it, the graph disappears. ggplotly(ggplot(data = data, aes(x = x, y = y)) + geom_bar(stat = "identity")) ggplotly doesn't work I get a warning message

How to make a choropleth map with a slider using Plotly?

与世无争的帅哥 提交于 2019-12-04 14:14:37
问题 I'm recreating the example choropleth and trying to add a slider that, when dragged, would change from year to year. Another user asked a similar question but they didn't receive a reply. I did some more searching and found an example where the user generated random values for the additional years and created a slider but it's in JavaScript and I'm not sure how to translate it into Python. Here's the code in JavaScript: Plotly.d3.csv('https://raw.githubusercontent.com/plotly/datasets/master

Plotly: How can I change the format of hover-on labels?

拥有回忆 提交于 2019-12-04 13:19:13
问题 I've looked through online documentation, but couldn't find how to change the format of hover-on labels: For example, if I'd like to display the number as "~611 thousand" or something of the sort. 回答1: Plotly tick and hover formatting are fully customizable using the python / d3 formatting language. From an API, use axis attributes 'tickformat' and 'hoverformat' to set the behavior. For example, this graph has 'layout.yaxis.hoverformat': ',f' . From the web app, input your formatting specs

How to plot normal distribution with percentage of data as label in each band/bin?

醉酒当歌 提交于 2019-12-04 12:58:41
While plotting normal distribution graph of data, how can we put labels like in image below for percentage of data in each bin where each band has a width of 1 standard deviation using matplotlib/seaborn or plotly ? Currently, im plotting like this: hmean = np.mean(data) hstd = np.std(data) pdf = stats.norm.pdf(data, hmean, hstd) plt.plot(data, pdf) Although I've labelled the percentages between the quartiles, this bit of code may be helpful to do the same for the standard deviations. import numpy as np import scipy import pandas as pd from scipy.stats import norm import matplotlib.pyplot as

On shiny app ggplotly() renders half the size of plot_ly(). How to fix that?

馋奶兔 提交于 2019-12-04 12:44:50
A plot's width is less than half when using ggplotly vs plot_ly to generate a plotly in a shiny app. Why is that? Is there a way to fix it so that ggplotly produces the plot with the same width as plot_ly or ggplot2? I have tried using the width parameter but that doesn't fix it. Output from the shiny app: library(shiny) library(plotly) library(ggplot2) ui <- fluidPage( titlePanel("plotly with shiny"), mainPanel( h4("Using ggplotly:"), plotlyOutput("ggplotly", width = "200"), h4("Using native plotly:"), plotlyOutput("plotly"), h4("Using ggplot:"), plotOutput("ggplot") ) ) server <- function

Plotting Pandas Multiindex Bar Chart

一个人想着一个人 提交于 2019-12-04 12:43:25
问题 How can I plot a Python Pandas multiindex dataframe as a bar chart with group labels? Do any of the plotting libraries directly support this? This SO post shows a custom solution using matplotlib, but is there direct support for it? As an example: quarter company Q1 Blue 100 Green 300 Q2 Blue 200 Green 350 Q3 Blue 300 Green 400 Q4 Blue 400 Green 450 Name: count, dtype: int64 ...can this dataframe be plotted with group labels like this? Thanks in advance, Rafi 回答1: import pandas as pd data =

Plotly: Plot multiple figures as subplots

江枫思渺然 提交于 2019-12-04 11:28:25
问题 These resources show how to take data from a single Pandas DataFrame and plot different columns subplots on a Plotly graph. I'm interested in creating figures from separate DataFrames and plotting them to the same graph as subplots. Is this possible with Plotly? https://plot.ly/python/subplots/ https://plot.ly/pandas/subplots/ I'm creating each figure from a dataframe like this: import pandas as pd import cufflinks as cf from plotly.offline import download_plotlyjs, plot,iplot cf.go_offline()

Adding text annotation to a clustering scatter plot (tSNE)

丶灬走出姿态 提交于 2019-12-04 11:22:51
I have XY data (a 2D tSNE embedding of high dimensional data) which I'd like to scatter plot . The data are assigned to several cluster s, so I'd like to color code the points by cluster and then add a single label for each cluster , that has the same color coding as the cluster s, and is located outside (as much as possible) from the cluster 's points. Any idea how to do this using R in either ggplot2 and ggrepel or plotly ? Here's the example data (the XY coordinates and cluster assignments are in df and the labels in label.df ) and the ggplot2 part of it: library(dplyr) library(ggplot2) set

How do I get data from selected points in an offline plotly python jupyter notebook?

北战南征 提交于 2019-12-04 10:22:05
Example code: from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot import plotly.graph_objs as go import numpy as np N = 30 random_x = np.random.randn(N) random_y = np.random.randn(N) # Create a trace trace = go.Scatter( x = random_x, y = random_y, mode = 'markers' ) data = [trace] # Plot and embed in ipython notebook! iplot(data, filename='basic-scatter') [ ] How do I get a copy of the x,y data, or the indices from the selection? So if you want to use javascript in Jupyter notebooks you have two options. Using the display(HTML()) method for rendering html inside