标签: plotly

为 Plotly 图表生成下拉菜单

这是我计算 10 只股票的股票波动率的代码:

   ##------------producing stock volatility plot---------##

p1 = ggplot(Closed_Price_Return, aes(Date, R.BPCL)) + geom_line(color = "blue") + 
     theme_bw()
p2 = ggplot(Closed_Price_Return, aes(Date, R.TCS)) + geom_line(color = "green") +
     theme_bw()
p3 = ggplot(Closed_Price_Return, aes(Date, R.CIPLA)) + geom_line(color = "red") +
     theme_bw()
p4 = ggplot(Closed_Price_Return, aes(Date, R.EICHER)) + geom_line(color = "pink") +
     theme_bw()
p5 = ggplot(Closed_Price_Return, aes(Date, R.INFY)) + geom_line(color = "yellow") +
     theme_bw()
p6 = ggplot(Closed_Price_Return, aes(Date, R.LT)) + geom_line(color = "purple") +
     theme_bw()
p7 = ggplot(Closed_Price_Return, aes(Date, R.MARUTI)) + geom_line(color …
Run Code Online (Sandbox Code Playgroud)

r plotly

0
推荐指数
1
解决办法
4195
查看次数

Plotly.js 创建堆叠和分组条形图

如何在Plotly.js上创建带有分组和堆叠条形的条形图?我需要这样的结构: 带有堆叠和分组图表的条形图

javascript plotly plotly.js

0
推荐指数
1
解决办法
8728
查看次数

情节中的刻面标签

我想更改plotly(_express)情节中的方面标签。这是情节:

import plotly.express as px
tips = px.data.tips()
fig = px.scatter(tips, x="total_bill", y="tip", color="smoker", facet_col="sex")
fig.show()
Run Code Online (Sandbox Code Playgroud)

我想要的是sex=从标签中删除。

plotly plotly-python

0
推荐指数
1
解决办法
2698
查看次数

如何使绘图条形子图显示堆栈的颜色,而不是迹线的颜色

我想根据每个数据帧中名为“types”的列为条形堆栈着色,但我不知道在哪里设置此参数(在 Plotly Express API 中有该参数color)。

奇怪的是,Plotly 已经用堆栈标记了条形图,但根据跟踪,[理所应当]以相同的方式对所有条形图着色:

from plotly.subplots import make_subplots
import plotly.graph_objects as go

fig = make_subplots(rows=1, cols=2)
fig.add_trace(go.Bar(x = grouped_A["Working Days"], y = grouped_A["Total"], 1, 1)
fig.add_trace(go.Bar(x = grouped_B["Working Days"], y = grouped_B["Total"], 1, 2)

fig.show()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

python plot plotly

0
推荐指数
1
解决办法
2040
查看次数

使用 Dash-Cytoscape 更改单个节点大小

我已经使用 Dash-Cytoscape 两天了,我尝试了很多方法来单独更改节点大小。我试过这个,但没有用:

import dash
import dash_cytoscape as cyto
import dash_html_components as html

app = dash.Dash(__name__)
app.layout = html.Div([
    cyto.Cytoscape(
        id="cytospace",
        elements=[
            {'data': {'id': 'one', 'label': 'Node 1'}, 'position': {'x': 50, 'y': 50}, 'size':20},
            {'data': {'id': 'two', 'label': 'Node 2'}, 'position': {'x': 200, 'y': 200}, 'size':70},
            {'data': {'source': 'one', 'target': 'two','label': 'Node 1 to 2'}}
        ],
        layout={'name':'preset'},
        style={'height': '95vh',
               'width': '100%'}
    )
])

if __name__ == "__main__":
    app.run_server(debug=True)
Run Code Online (Sandbox Code Playgroud)

python cytoscape plotly plotly-dash

0
推荐指数
1
解决办法
1565
查看次数

提高情节动画的速度

我使用 plotly express 的函数 choropleth() 创建了一个 choropleth 地图,代码如下。


fig = px.choropleth(df_countrydate, 
                    locations="Country", 
                    locationmode = "country names",
                    color="Confirmed", 
                    hover_name="Country", 
                    animation_frame="Date",
                    color_continuous_scale="Reds"
                   )
fig.update_layout(
    title_text = 'Global Spread of Coronavirus',
    title_x = 0.5,
    geo=dict(
        showframe = False,
        showcoastlines = False,
    ))

iplot(fig)
Run Code Online (Sandbox Code Playgroud)

这是一张动态地图,我想知道是否可以在我点击播放时加快从一个日期到下一个日期的转换。

python plotly choropleth

0
推荐指数
1
解决办法
1488
查看次数

如何在plotly中为图表创建带有换行符的标题

我需要用换行符在 plotly 上创建一个图。最好顶部的文本大于第二行,但不是必需的。

fig.update_layout(
    title=go.layout.Title(
        text=title,
        xref="paper",
        x=0.5,
    ),

Run Code Online (Sandbox Code Playgroud)

对于我尝试过的标题

title = "Hello \n World"
title = "Hello" + "\n" + "World"
title = "$Hello \\ World$"
title = "$Hello \newline World$"
Run Code Online (Sandbox Code Playgroud)

所有运行都没有错误,但换行符被忽略。

我不确定如何实现这一点。感谢您的帮助。

python plotly plotly-python

0
推荐指数
1
解决办法
1582
查看次数

在 R Shiny 应用程序中渲染 ggplot2 和绘图对象

我有一个R shiny应用程序使用R和来生成plotlyggplot2显示数字。

因为渲染plotly图形shiny需要plotly函数,所以renderPlotly图形ggplot2会转换为零件plotly中的对象renderPlotly,这会让它们有点混乱。

这是一个例子。首先,生成一些数据:

set.seed(1)

meta.df <- data.frame(cell = c(paste0("c_",1:1000,"_1w"), paste0("c_",1:1000,"_2w"), paste0("c_",1:1000,"_3w")),
                      cluster = c(sample(c("cl1","cl2","cl3"),1000,replace=T)),
                      age = c(rep(1,1000),rep(2,1000),rep(3,1000)),
                      x = rnorm(3000), y = rnorm(3000))

expression.mat <- cbind(matrix(rnorm(20*1000,1,1), nrow=20, ncol=1000, dimnames=list(paste0("g",1:20),meta.df$cell[1:1000])),
                        matrix(rnorm(20*1000,2,1), nrow=20, ncol=1000, dimnames=list(paste0("g",1:20),meta.df$cell[1001:2000])),
                        matrix(rnorm(20*1000,3,1), nrow=20, ncol=1000, dimnames=list(paste0("g",1:20),meta.df$cell[2001:3000])))
Run Code Online (Sandbox Code Playgroud)

这是应用程序代码:

library(shiny)
library(dplyr)
library(ggplot2)
library(ggpmisc)

server <- function(input, output, session)
{
  output$gene <- renderUI({
      selectInput("gene", "Select Gene to Display", choices …
Run Code Online (Sandbox Code Playgroud)

r render ggplot2 shiny plotly

0
推荐指数
1
解决办法
2123
查看次数

获取streamlit中上传文件的原始名称

我正在使用 streamlit 制作一个基本的可视化应用程序来比较两个数据集,为此我使用了 Marc Skov 从 streamlit 画廊制作的以下示例:

from typing import Dict

import streamlit as st


@st.cache(allow_output_mutation=True)
def get_static_store() -> Dict:
    """This dictionary is initialized once and can be used to store the files uploaded"""
    return {}


def main():
    """Run this function to run the app"""
    static_store = get_static_store()

    st.info(__doc__)
    result = st.file_uploader("Upload", type="py")
    if result:
        # Process you file here
        value = result.getvalue()

        # And add it to the static_store if not already in
        if not value in static_store.values(): …
Run Code Online (Sandbox Code Playgroud)

python plotly streamlit

0
推荐指数
1
解决办法
1971
查看次数

折线图中缺少数据点

Plotly 图形上缺少用于绘制图形的 x 和 y 列表中的数据点。我不知道为什么。

x_axist_list 是年-周格式的列表。例如,2019-43 就是 2019 年的第 43 周。

x_axis_list = ['2019-00', '2019-01', '2019-02',.....'2019-54']
y_axis_list = [0,0,0,....1,2,0,0]
Run Code Online (Sandbox Code Playgroud)

当我使用 Plotly 绘制出来时:

my_fig = px.line(x=x_axis_list, y=y_axis_list,\
labels=dict(time_from_db="Time", \
num_of_accidents_from_db="Num of Accidents"), \
title="Number of Accidents Per Week")

dcc.Graph(id='my_fig', figure=my_fig)
Run Code Online (Sandbox Code Playgroud)

我得到奇怪的折线图,如下图所示。 在此输入图像描述

plotly plotly-dash

0
推荐指数
1
解决办法
5631
查看次数