我是该框架的新手Plotly Dash,并尝试构建一个简单的仪表板:
允许用户上传 CSV 文件以进行图形分析。
根据步骤 #1 中上传的文件创建 Pandas 数据框。
2a. 如果尚未选择 CSV 文件(以及生成的数据框),则不渲染任何内容。
根据上述数据框中包含的数据渲染基本条形图(或散点图、热图等)。
我的 CSV 文件中的数据类似于以下内容:
df = pd.DataFrame({'Make':['Ford', 'Ford', 'Ford', 'BMW', 'BMW', 'BMW', Mercedes', 'Mercedes', 'Mercedes'],
'Score':['88.6', '76.6', '100', '79.1', '86.8', '96.4', '97.3', '98.7', '98.5'],
'Dimension':['Speed', 'MPG', 'Styling', 'Speed', 'MPG', 'Styling', 'Speed', 'MPG', 'Styling'],
'Month':['Apr-19', 'Apr-19', 'Apr-19', 'Apr-19', 'Apr-19', 'Apr-19', 'Apr-19', 'Apr-19', 'Apr-19']})
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
import base64
import datetime
import io
import dash
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_html_components as …Run Code Online (Sandbox Code Playgroud) 在 Plotly 中,使用 Scattermapbox,有没有办法在标记上方和下方显示一些文本?
目前,仅当我将鼠标悬停在标记上时才会显示文本,并且该图仅显示我想要显示的文本的一部分。
我的输入数据框df_area如下。我想显示列name和列中包含的文本forecast。
name latitude longitude forecast
0 "AK" 2.675000 203.139000 "Cloudy"
1 "Bd" 2.621000 203.224000 "Cloudy"
Run Code Online (Sandbox Code Playgroud)
但是,我目前只能显示该forecast列中的文本。
fig = go.Figure(go.Scattermapbox(
lat=df_area["latitude"],
lon=df_area["longitude"],
mode="markers+text",
marker={"size": 10},
text=df_area["forecast"]))
Run Code Online (Sandbox Code Playgroud) 我想使用一个绘图下拉事件来显示不同的分组箱线图,但是我还无法实现这一点:
第一个图显示了 dropdown = "4" 的plotly 的预期输出(使用 ggplot 获得)。第二个情节是我得到的......
library(tidyverse)
library(plotly)
dat <- mtcars %>%
filter(cyl == 4 | carb == 4) %>%
group_by(cyl, carb, am) %>%
summarise(boxplot= list( setNames(boxplot.stats(disp)$stats,
c('lower_whisker','lower_hinge','median','upper_hinge','upper_whisker')) )) %>%
unnest_wider(boxplot) %>%
arrange(cyl, carb, am) %>%
ungroup() %>%
mutate_at(vars(cyl, carb, am), as.character)
cylinders <- unique(dat$cyl)
dat %>%
filter(cyl == 4) %>%
ggplot(aes(
x = carb,
lower = lower_hinge,
upper = upper_hinge,
middle = median,
ymin = lower_whisker,
ymax = upper_whisker,
colour = am)) +
geom_boxplot(stat = "identity") …Run Code Online (Sandbox Code Playgroud) 我正在使用该px.bar()函数来Plotly Express创建一些简单的条形图。
我的代码如下:
import plotly.express as px
import pandas as pd
test_df = pd.DataFrame({'Manufacturer':['Ford', 'Ford', 'Mercedes', 'BMW', 'Ford', 'Mercedes', 'BMW', 'Ford', 'Mercedes', 'BMW', 'Ford', 'Mercedes', 'BMW', 'Ford', 'Mercedes', 'BMW', 'Ford', 'Mercedes', 'BMW'],
'Metric':['Orders', 'Orders', 'Orders', 'Orders', 'Orders', 'Orders', 'Orders', 'Sales', 'Sales', 'Sales', 'Sales', 'Sales', 'Sales', 'Warranty', 'Warranty', 'Warranty', 'Warranty', 'Warranty', 'Warranty'],
'Sector':['Germany', 'Germany', 'Germany', 'Germany', 'USA', 'USA', 'USA', 'Germany', 'Germany', 'Germany', 'USA', 'USA', 'USA', 'Germany', 'Germany', 'Germany', 'USA', 'USA', 'USA'],
'Value':[45000, 70000, 90000, 65000, 40000, 65000, …Run Code Online (Sandbox Code Playgroud) 我想修改绘图直方图的悬停模板。到目前为止,无法找到一种方法: 对给定的值进行舍入 删除直方图的名称(此处:“2012”、“2013”) 添加名称以指示值代表什么
所需的悬停文本:
Bin-range: -1.24, 3.31
Run Code Online (Sandbox Code Playgroud)
或者
更好的选择(带连字符的范围):
Bin-range: -1.24 - 3.31
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
import plotly.figure_factory as ff
import numpy as np
import pandas as pd
df = pd.DataFrame({'2012': np.random.randn(200),
'2013': np.random.randn(200)+1})
fig = ff.create_distplot([df[c] for c in df.columns],
df.columns, bin_size=.25, show_rug=False)
fig.show()
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用绘图和破折号构建一个简单的网络仪表板。这是我想要获得的结构:
app = dash.Dash(__name__)
def Build_home_page():
"""
build_welcome_banner [summary]
[extended_summary]
Returns
-------
[type]
[description]
""" ""
return [
html.Div(
id="banner",
className="box",
children=[
html.Div(
id="welcome-user",
children=[
html.H1("WELCOME TO THE DATA SCIENCE"),
html.H1("AND MACHINE LEARNING PLATFORM"),
html.Hr(className="tickline"),
html.Br(),
html.P(id="welcome-text1",
children= [
"That provides you with the tools that allow you to explore your data seemlessly and"
]),
html.P(id= "welcome-text2",
children= [
"get actionable insights from your data and allows you to easily apply Machine learning models to make predictions with your data" …Run Code Online (Sandbox Code Playgroud) 我用 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) 我正在寻找将ggraph对象转换为迭代力网络的示例或教程。
首先我尝试plotly使用函数转换为对象plotly::ggplotly。但似乎plotly不能很好地处理这种转换并且错过了边缘。
但我发现network3D,我可以将一个igraph对象转换为一个network3D对象,但这不是我想要的。而且这个包的功能太冗长了。无论如何,没有从ggraph对象转换的函数。
所以,我的问题非常基本,但是...您知道创建交互式ggraph网络的任何方法吗?
谢谢
plotly ×10
python ×6
plotly-dash ×4
r ×2
bounding-box ×1
boxplot ×1
force-layout ×1
ggraph ×1
interactive ×1
mapping ×1
pandas ×1
plot ×1
python-3.x ×1