这是我计算 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) 如何在Plotly.js上创建带有分组和堆叠条形的条形图?我需要这样的结构: 带有堆叠和分组图表的条形图
我想更改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=从标签中删除。
我想根据每个数据帧中名为“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)
我已经使用 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) 我使用 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)
这是一张动态地图,我想知道是否可以在我点击播放时加快从一个日期到下一个日期的转换。
我需要用换行符在 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)
所有运行都没有错误,但换行符被忽略。
我不确定如何实现这一点。感谢您的帮助。
我有一个R shiny应用程序使用R和来生成plotly和ggplot2显示数字。
因为渲染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) 我正在使用 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) 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 ×10
python ×5
plotly-dash ×2
r ×2
choropleth ×1
cytoscape ×1
ggplot2 ×1
javascript ×1
plot ×1
plotly.js ×1
render ×1
shiny ×1
streamlit ×1