https://plot.ly/python/bar-charts/#bar-chart-with-line-plot
我想使用plotly和iPython创建一个带有线条图的条形图,如上例所示.另一方面,我希望条形图是一个水平堆积条形图,如下面的例子中使用plotly和iPython.我该怎么做呢?
https://plot.ly/python/bar-charts/#colored-bar-chart
y_saving_yes = [1, 2, 4, 6, 7, 7]
y_saving_no = [10, 10, 10, 10, 10, 10]
y_net_worth = [93453, 81666, 69889, 78381, 141395, 92969]
x_saving = ['Premium', 'Spot Shadow', 'Slow Motion', 'Highlight Music','Extra Text', 'Top Play']
x_net_worth = ['Premium', 'Spot Shadow', 'Slow Motion', 'Highlight Music','Extra Text', 'Top Play']
trace1 = Bar(
x=y_saving,
y=x_saving,
marker=Marker(
color='rgba(50, 171, 96, 0.6)',
line=Line(
color='rgba(50, 171, 96, 1.0)',
width=1,
),
),
name='Highlight Properties',
orientation='h',
)
trace2 = Bar(
x=y_saving,
y=x_saving,
marker=Marker(
color='rgba(50, …Run Code Online (Sandbox Code Playgroud) 现在我正在使用plot.ly javascript库来显示一组数字.我想在每次迭代中更新这个图.我尝试Plotly.newPlot('id',data);在值更改后,但每次重新定义绘图对象需要时间.
我浏览了plot.ly文档,但没有为我的案例找到解决方案.
我想在每次中断时更新图形,也许我需要在调用迭代函数后更新绘图200次.针对此问题的任何解决方案/建议?如果有一个适合这种情况,我可以使用另一个绘图库.
有没有办法在剧情中改变R的图例大小?我没有遇到这个选项.我查看了关于传说的文档,https://plot.ly/r/legend/,但它没有提到这一点.
我希望控制x轴上出现的刻度线.以下代码以5的顺序(5,10,15 ... 30)放置刻度线
library(plotly)
df <- data.frame(x = 1:30,
y = sample(100:300, size = 30, replace = T))
p <- plot_ly(data = df, x = x, y = y, type = 'line') %>%
layout(title = 'Example plot')
p
Run Code Online (Sandbox Code Playgroud)
我需要按照6,12,18,24,30的顺序放置它们.我一直在浏览文档,但我似乎无法找到我需要的东西.在ggplot2这可以通过scale_x_continuous(breaks=c(6,12,18,24,30).
我有一个闪亮的应用程序,如下所示:
server.R:
shinyServer(function(input, output) {
output$trendPlot <- renderPlotly({
plot_ly(movies, x = length, y=rating, mode='markers', color=as.factor(year), colors = c("#132B43", "#56B1F7")) -> plott
plott
})
})
Run Code Online (Sandbox Code Playgroud)
ui.R:
library(shiny)
library(plotly)
library(ggplot2movies) # Needed for the 'movies' data set
shinyUI(fluidPage(
titlePanel("Movie Ratings!"),
mainPanel(
plotlyOutput("trendPlot")
)
))
Run Code Online (Sandbox Code Playgroud)
这会产生警告:
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
Run Code Online (Sandbox Code Playgroud)
我想抑制此警告,因为它不必要地使我的日志混乱(是的,我知道如何通过解决问题来实际消除此警告。但这只是出于说明目的。在我真正的闪亮应用中,没有摆脱警告)。
结束语最后plott在renderPlotly()中suppressWarnings()不起作用。更改plott为 …
我没想到会出现此错误(“ AttributeError:模块'plotly'没有属性'plot'”),并且无法找到确切的错误。我认为这不是确切的错误,因为对于此特定练习,显然具有绘图能力,并且在我的数据未正确格式化的某个地方。
我愿意就新方法提出建议。这就是我所使用的,因为它易于遵循,它是我最终想要的,并且是集中式的。
错误发生在最后一行 py.plot( fig, filename='d3-cloropleth-map' )
我已经从示例中复制了代码:美国Choropleth地图
这是我的代码:
import plotly as py
import pandas as pd
import numpy as np
py.tools.set_credentials_file(username='user', api_key='xxxXxxXxxx')
df = pd.DataFrame.from_csv("C:/Users/d/Documents/Personal/Python Scripts/Python/Connect.csv")
for col in df.columns:
df[col] = df[col].astype(str)
df[['Open Balance','Amount', 'Aging']] = df[['Open Balance','Amount',
'Aging']].apply(pd.to_numeric, errors='ignore')
df[['Date', 'Due Date']] = df[['Date','Due Date']].apply(pd.to_datetime)
state_total_byitem = df.groupby(by = ['State', 'Item']).agg({'Open Balance':'sum','Amount':'sum','Paid':'count','Aging':'mean'})
sti = state_total_byitem
sti.reset_index(level=['State', 'Item'], inplace=True)
for col in sti.columns:
sti[col] = sti[col].astype(str)
sti['text'] = 'State ' + sti['State'] + ' Item ' …Run Code Online (Sandbox Code Playgroud) 有没有人有在Github托管的网站中嵌入交互式地块的经验?我已经读过github不会渲染Bokeh,Plotly等的交互式图,但是其他站点似乎能够做到吗?理想情况下,我想做的是上传一个包含这些图的Jupyter笔记本,并将它们显示在我的github博客上。但是由于某种原因,它们不会渲染,而其他一切看起来都很好。谢谢!
我需要为条形图中的每个组手动设置颜色。我目前有填充=时间,这目前正在确定颜色。我们有5个品牌,每个品牌分别有2个月的价值。我需要按品牌分组,但是还需要一种显示哪个条形表示哪个月(时间)的方法,我目前可以执行此操作,但是我想为每个条形组上色。例如。brand1条=红色,brand2条=蓝色ect,同时仍有填充时间=时间
这是我的代码:
colors <- c("#98999B", "#F4C400", "#CB003D", "#6BABE5", "#E65400", "#542C82")
time <- c("February 2017","March 2017","February 2017","March 2017","February 2017","March 2017","February 2017","March 2017","February 2017","March 2017")
value <- as.numeric(c("3.08","3.64","1.61","1.81","-1.02","-1.09","-5.23","-5.08","-1.51","-1.43"))
brand <- c("brand1","brand1","brand2","brand2","brand3","brand3","brand4","brand4","brand5","brand5")
Monthly_BMS_df <- as.data.table(cbind(time,value,brand))
bar <- ggplot(Monthly_BMS_df, aes(brand, value, fill = time)) +
geom_bar(stat="identity", position = "dodge") +
theme(legend.position='none') + scale_fill_manual(values=colors)
ggplotly(bar, width=1000,height=350)
Run Code Online (Sandbox Code Playgroud) 如何转换这样的图形:
df1 = pd.read_excel("C:/Users/Tim/PycharmProjects/firstdash/Analysis.xlsx")
html.Div(
[
html.H3("Graph 1"),
dcc.Graph(
id="g1",
figure={
"data": [
go.Bar(
x=df1["Marketsegment"],
y=df1["test"],
)]})],)
Run Code Online (Sandbox Code Playgroud)
进入堆积的条形图。因此,一个包含总住宅和企业的酒吧以不同的颜色堆叠在一起。
我似乎无法以某种方式使其工作。
我发现的只是这种语法,不适用于我:
trace1 = go.Bar(
x=['giraffes', 'orangutans', 'monkeys'],
y=[20, 14, 23],
name='SF Zoo'
)
trace2 = go.Bar(
x=['giraffes', 'orangutans', 'monkeys'],
y=[12, 18, 29],
name='LA Zoo'
)
data = [trace1, trace2]
layout = go.Layout(
barmode='group'
)
Run Code Online (Sandbox Code Playgroud) 我有XY我想使用曲线图的数据scatter plot,用R的plotly包.
set.seed(1)
df <- data.frame(x=c(rnorm(30,1,1),rnorm(30,5,1),rnorm(30,9,1)),
y=c(rnorm(30,1,1),rnorm(30,5,1),rnorm(30,9,1)),
group=c(rep("A",30),rep("B",30),rep("C",30)),score=runif(90,0,1))
Run Code Online (Sandbox Code Playgroud)
每个点都分配给三个组中的一个(df$group)并且在该[0,1]范围内具有分数.
我正在寻找一种方法来绘制数据图形,使每组用不同颜色着色,但颜色(或强度)的阴影反映了分数.
所以我认为这会奏效:
library(dplyr)
library(plotly)
plot_ly(marker=list(size=10),type='scatter',mode="markers",x=~df$x,y=~df$y,color=~df$score,colors=c("#66C2A5","#FC8D62","#8DA0CB")) %>%
layout(xaxis=list(title="X",zeroline=F,showticklabels=F),yaxis=list(title="Y",zeroline=F,showticklabels=F))
Run Code Online (Sandbox Code Playgroud)
如果我只是通过group以下颜色代码:
plot_ly(marker=list(size=10),type='scatter',mode="markers",x=~df$x,y=~df$y,color=~df$group,colors=c("#66C2A5","#FC8D62","#8DA0CB")) %>%
layout(xaxis=list(title="X",zeroline=F,showticklabels=F),yaxis=list(title="Y",zeroline=F,showticklabels=F))
Run Code Online (Sandbox Code Playgroud)
所以看起来它正在混合group颜色和score渐变.
我正在寻找的是有绿色的色调(比如从有色左下方组gray到darkgreen)对应于score(从低到高),与同为分别在橙色和蓝色,其他两组.
plotly ×10
r ×5
bar-chart ×2
python ×2
python-3.x ×2
bokeh ×1
ggplot2 ×1
github ×1
gradient ×1
ipython ×1
javascript ×1
linegraph ×1
plotly-dash ×1
r-plotly ×1
scatter-plot ×1
shiny ×1
subplot ×1