我使用的是 3.6.3 R 版本。编译 R.mrd 时出现以下错误:\n \n因此图表没有出现在仪表板中。\n请提供任何帮助Registered S3 method overwritten by 'data.table':\n method from\n print.data.table
\nRegistered S3 method overwritten by 'htmlwidgets':\n method from
\n print.htmlwidget tools:rstudio\nRegistered S3 method overwritten by 'dplyr':\n method from\n print.rowwise_df \nle package \xef\xbf\xbdflexdashboard\xef\xbf\xbd a \xef\xbf\xbdt\xef\xbf\xbd compil\xef\xbf\xbd avec la version R 3.6.3Registered S3 methods overwritten by 'htmltools':\n method from
\n print.html tools:rstudio\n print.shiny.tag tools:rstudio\n print.shiny.tag.list tools:rstudio
我正在尝试在绘图破折号应用程序中使用自定义标记类型。我定义我的图表如下:
html.Div(
[
dcc.Graph(
figure=dict(
data=[
dict(
x=[5, 10, 20, 15],
y=[1, 2, 1, 3],
type='scatter',
mode='markers',
marker=dict(
color='Red',
symbol='line-ns',
size=20,
opacity=1,
),
),
],
layout=dict(),
),
id='my-graph',
),
],
),
Run Code Online (Sandbox Code Playgroud)
当我使用symbol='square'它时,它的工作原理如左下所示,但是当symbol='line-ns'悬停时,该符号是不可见的。
基本符号似乎可以工作,但大多数不太常见的符号似乎都有这个问题。
查看此处的文档:
https://plotly.com/python/marker-style/#custom-marker-symbols
我在笔记本中有一个symbol='line-ns'使用图形对象工作的示例:
import plotly.graph_objects as go
# Generate example data
import numpy as np
# Build figure
fig = go.Figure()
# Add trace with large markers
fig.add_trace(
go.Scatter(
mode='markers',
x=[2, 2],
y=[4.25, 4.75],
marker=dict(
symbol='line-ns',
color='rgba(135, 206, 250, 0.5)', …Run Code Online (Sandbox Code Playgroud) 我需要在图中描绘一个“断轴”,因为有些值很大。举个例子,考虑:
import plotly.graph_objects as go
import numpy as np
y=np.arange(20)
y[0]=1000
go.Figure(go.Bar(
y=y
))
Run Code Online (Sandbox Code Playgroud)
This Question讨论了与 matplotlib 相同的内容,但我需要使用plotly。
我有两个示例数据框,如下所示
library(shiny)
df1 <- data.frame(words = c("bat", "vat","cat","mat"), count = c(3420, 2098, 2003, 1501), words_count = c("bat (3420)","vat (2098)", "cat (2003)", "mat (1501)"), stringsAsFactors = FALSE)
df2 <- data.frame(class = c("A","B","C","D"), bat = c(10,0,30,20), vat = c(0,0,10,30), cat = c(20,30,0,10), mat = c(20,20,0,0), stringsAsFactors = FALSE)
Run Code Online (Sandbox Code Playgroud)
使用下面的代码,我想从下拉菜单中提取列名称(由 df1 制成),并使用提取的值在绘图中绘制条形图,使用提取的值作为 df2 中的列。我正在做这个是 Rmd。
inputPanel(
selectInput("words", label = "Choose the word",
choices = df1$words_count,
selected = df1$words_count[1], width = '100%')
)
renderPlot({
# Extract the word from drop down
col_word <- df1 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用plotly为单个图中的多个数据帧绘制折线图。我的代码是:
import plotly.express as px
labels=category_names[:10]
for category in category_names[:10]:
df_b=df1[df1['Country/Region']==category]
fig=px.line(df_b, x="Date", y="Confirmed",labels="Country/Region")
print(category)
fig.show()
Run Code Online (Sandbox Code Playgroud)
但是,通过使用上面的代码,我只能获取 for 循环最后一次迭代的线图。
电流输出:
期望的输出:
请帮助我的代码!
我正在学习使用 Plotly,并且在每个示例中,布局均使用 Fig.update_layout(...
https://plotly.com/python/text-and-annotations/
我想确切地知道在那里可以做的一切。
我在哪里可以找到详尽的论点列表
fig.update_layout( ???
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用plotly 复制我在matplotlib 中制作的以下箱线图:

我的数据位于从 Excel 文件导入的非常简单的数据框中,如下所示:

正如您所看到的,我希望在 x 轴和 y 轴上有不同的条件,涵盖从 0 到 10 的范围,并为每个条件绘制不同的箱线图,并具有自己的均值、SD 等。但是,当我尝试时下面的代码我得到一个非常奇怪的输出:
import plotly.express as px
conditions = df1.keys() #all conditions, df1 being my DataFrame
conditions=list(conditions)
fig = px.box(df1, x = conditions)
fig.show()
Run Code Online (Sandbox Code Playgroud)
输出:

任何人都知道我必须做什么才能得到类似的情节,就像我用 matplotlib 但用plotly得到的那样?
我用 Python 创建了一个简单的 Plotly 图表,并且可以非常轻松地更改模式栏选项。但是,当我尝试将相同的图表发布到 Chart-Studio 时,并非所有模式栏配置都有效。有任何想法吗?
这是代码:
import pandas as pd
import numpy as np
import plotly.graph_objects as go
df = pd.DataFrame({'a':[2,4,6,8,10],'b':[3,6,9,12,15]})
fig = go.Figure()
fig.add_trace(go.Scatter(x=df.index, y=df['a'], mode='lines', name='a', line=dict(color='dodgerblue', dash='solid')))
fig.add_trace(go.Scatter(x=df.index, y=df['b'], mode='lines', name='b', line=dict(color='lightsalmon', dash='dash')))
fig.update_layout(
title='a and b',
autosize=False,
width=500,
height=500,
newshape=dict(line_color='mediumaquamarine', line_width=2, opacity=1)
)
config = {
'modeBarButtonsToAdd' : ['drawline', 'drawopenpath', 'drawrect', 'eraseshape'],
'displaylogo' : False
}
fig.show(config=config)
Run Code Online (Sandbox Code Playgroud)
出现的图形已删除徽标,并且模式栏上的附加按钮按其应有的方式显示...
但是,如果我尝试将其发布到 Chart-Studio:
import chart_studio.plotly as py
import chart_studio
chart_studio.tools.set_credentials_file(username='xxxxx', api_key='#####')
py.plot(fig, filename='a and b', auto_open=False, config=config) …Run Code Online (Sandbox Code Playgroud) 我想更改plotly.express条形图图例中项目的顺序。例如,我想在此图上显示“午餐前的晚餐”(当前的行为对于水平条形图尤其尴尬,因为条形的顺序与图例顺序相反):
import plotly.express as px
df = px.data.tips()
# Sort to put dinner on top.
df.sort_values('time', ascending=False, inplace=True)
fig = px.bar(df, y='sex', x='total_bill', color='time', barmode='group',
orientation='h')
fig.update_layout(yaxis={'categoryorder': 'total ascending'})
fig.show()
Run Code Online (Sandbox Code Playgroud)
我正在尝试计算美国各种变量的平均人口中心,因此我的第一步是按县计算过去 10 年的人口,看看它们是否与该图的人口普查地图相匹配(至少粗略地说,因为人口普查使用的是更精细的地理分辨率。)正如你所期望的,这是一种极度延迟的昭昭命运:
(如果有人好奇的话,根据许多人口中心计算这些点的公式位于此处的第 2 页。)
我正在从 R/RStudio 迁移到 Jupyter,使用 pandas、plotly、numpy 等。我通常是一名 JavaScript 工程师,但我对 Python 很满意,并且比 R 更喜欢它!我能够使用上这个精彩教程plotly.graph_objects.Scattergeo中的机场地图示例来计算看似相似的点,但我陷入了国家分辨率,所以我无法告诉我做得有多好:
当然,我可以手动缩放,但我真的很想了解如何默认仅关注密苏里州。我发现这个很有用的 CodePen,但是由于 Python 中有很多不同的优秀映射工具,我不确定如何移植 JS。
我当前的地图基于上述教程,设置了基本绘图,然后在第二行中修改布局的范围 - 我不确定这是否是 的标准plotly,或者只是为了方便。
尽管我很欣赏 Python,但直接查看文档update_layout有点像兔子洞:) 我不介意指定视口的纬度/经度边界,尽管直接说“密苏里州”会很整洁。我意识到这很简单——只是需要一点学习曲线。
import pandas as pd
import plotly.graph_objects as go
meanCenters = pd.read_json('{"year": {"0": 2010, "1": 2011, "2": 2012, "3": 2013, "4": 2014, "5": 2015, "6": 2016, "7": 2017, "8": 2018, "9": 2019}, "lat": {"0": 37.52908501121699, "1": 37.51719645600817, "2": …Run Code Online (Sandbox Code Playgroud) plotly ×10
python ×7
r ×2
axis-labels ×1
bounding-box ×1
boxplot ×1
cran ×1
dashboard ×1
dataframe ×1
dplyr ×1
for-loop ×1
linegraph ×1
mapping ×1
matplotlib ×1
package ×1
plot ×1
plotly-dash ×1
python-3.x ×1