在阅读了与此问题相关的所有现有帖子后,我仍然无法解决它。
ModuleNotFoundError: No module named 'plotly'
Run Code Online (Sandbox Code Playgroud)
我已尝试以下所有方法:
pip3 install plotly
pip3 install plotly --upgrade
Run Code Online (Sandbox Code Playgroud)
以及通过以下方式卸载:
pip3 uninstall plotly
Run Code Online (Sandbox Code Playgroud)
再次重新安装它,我在终端上得到以下信息:
Requirement already satisfied, skipping upgrade: six in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from plotly) (1.11.0)
Requirement already satisfied, skipping upgrade: nbformat>=4.2 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from plotly) (4.4.0)
Requirement already satisfied, skipping upgrade: retrying>=1.3.3 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from plotly) (1.3.3)
Requirement already satisfied, skipping upgrade: urllib3<1.25,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from requests->plotly) (1.24.1)
Requirement already satisfied, skipping upgrade: idna<2.8,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from requests->plotly) (2.7)
Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 …Run Code Online (Sandbox Code Playgroud) 我试图返回一个条形图,但用于条形图的列根据下拉值选择而变化。我将字典返回到 graph.figure 输出,但收到以下错误;
dash.exceptions.InvalidCallbackReturnValue:
The callback for property \figure``
of component \graph-one` returned a value`
which is not JSON serializable.
In general, Dash properties can only be
dash components, strings, dictionaries, numbers, None,
or lists of those.
Run Code Online (Sandbox Code Playgroud)
我的返回值是一本字典。代码如下;
def create_grouped_bar(df):
return [
go.Bar(
x=df['date'],
y=df[col],
text=df[col],
hoverinfo='text+name',
name=col.title(),
)
for col in df.columns
]
@app.callback(
Output('graph-one', 'figure'),
[Input('filtered_df', 'children'),
Input('freq-radio', 'value'),
Input('graph-one-drop', 'value'),
Input('graph-one-radio', 'value')])
def update_graph(df_json, freq, cols, amount):
dff = pd.read_json(df_json, orient='split')
plot_cols = falls_dd_dict[cols]
plot_df = dff[['date_time_occurred']+plot_cols].copy() …Run Code Online (Sandbox Code Playgroud) 我有几个组的测量值,我想将它们绘制为小提琴图:
set.seed(1)
df <- data.frame(val = c(runif(100,1,5),runif(100,1,5),rep(0,100)),
group = c(rep("A",100),rep("B",100),rep("C",100)))
Run Code Online (Sandbox Code Playgroud)
使用R的ggplot2:
library(ggplot2)
ggplot(data = df, aes(x = group, y = val, color = group)) + geom_violin()
Run Code Online (Sandbox Code Playgroud)
R但是当我尝试使用's获得等效值时plotly:
library(plotly)
plot_ly(x = df$group, y = df$val, split = df$group, type = 'violin', box = list(visible = F), points = F, showlegend = T, color = df$group)
Run Code Online (Sandbox Code Playgroud)
“C”组获得一把充气/人造小提琴。
知道如何处理这个问题而不是使用 吗ggplotly?
考虑下面的简单示例。有没有一种方法可以格式化绘图工具提示,以便长文本标签在框中可见,而不是这个截断值的荒谬矩形?
library(ggplot2); library(plotly)
df <- data.frame(x = 1:10, y = 1:10, z = rep("the longggggggggggggggggggggggggggggestttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt labelllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll you can imagineeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", 10))
p <- ggplot(df, aes(x,y,label=z)) + geom_point()
ggplotly(p, tooltip = "label")
Run Code Online (Sandbox Code Playgroud)
有没有什么方法可以在 Plotly 甘特图中创建任务标签在条形图上和资源标签在 y 轴上?
的文档中没有这样的例子plotly.figure_factory.create_gantt。下面给出了理想图表的抽象示例:
我正在尝试为数据框中的每个类分配颜色,这是我的代码:
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
knn = KNeighborsClassifier(n_neighbors=7)
# fitting the model
knn.fit(X_train, y_train)
# predict the response
pred = knn.predict(X_test)
dfp = pd.DataFrame(X_test)
dfp.columns = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm']
dfp["PClass"] = pred
pyo.init_notebook_mode()
data = [go.Scatter(x=dfp['SepalLengthCm'], y=dfp['SepalWidthCm'],
text=dfp['PClass'],
mode='markers',
marker=dict(
color=dfp['PClass']))]
layout = go.Layout(title='Chart', hovermode='closest')
fig = go.Figure(data=data, layout=layout)
pyo.iplot(data)
Run Code Online (Sandbox Code Playgroud)
这是我的 df 的样子:
SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm PClass
6.1 2.8 4.7 1.2 Iris-versicolor
5.7 3.8 1.7 0.3 Iris-setosa
7.7 2.6 6.9 2.3 Iris-virginica
Run Code Online (Sandbox Code Playgroud)
所以问题是它没有根据 …
我有一个带有可删除行和列的破折号 DataTable 对象。我想根据可见行更新数字。我不确定如何创建回调以及要传递哪些参数。当在浏览器中删除行时,存储在表对象中的数据实际上可能不会改变。
from dash_table import DataTable
def lineplot(id, df, cols, title=None, xlabel=None, ylabel=None, x=None,
xaxis_type=None, yaxis_type=None, plotly_config=plotly_config,
):
if x is None:
x_values = df.index
xlabel = df.index.name
else:
x_values = df[x]
data = [{
'x': x_values,
'y': df[col],
'name': col } for col in cols]
layout = go.Layout(
title=go.layout.Title(
text=title,
xref='paper',
xanchor='center'
),
xaxis = go.layout.XAxis(
title=go.layout.xaxis.Title(
text=xlabel,
font=plotly_config['font'],
),
type=xaxis_type
),
yaxis=go.layout.YAxis(
title=go.layout.yaxis.Title(
text=ylabel,
font=plotly_config['font'],
),
type=yaxis_type
),
showlegend=True
)
return dcc.Graph(
id=id,
figure={'data': data,
'layout': layout}, …Run Code Online (Sandbox Code Playgroud) 我想更改plotly条形图中悬停框的位置。我希望它在栏上方弹出,而不是在左侧或右侧弹出。这可能吗?我一直在谷歌上搜索这个并盯着 Plotly R 参考页面几个小时,但没有运气。
这是一个示例:
library(dplyr)
library(plotly)
data.frame(x = 1:10, y = 1:10*10) %>%
plotly::plot_ly(data = .) %>%
plotly::add_trace(x = ~x,
y = ~y,
type = 'bar',
hoverinfo = "text",
text = ~y)
Run Code Online (Sandbox Code Playgroud) 以下跟踪在绘图中显示了一些文本。我想将此文本旋转到 90\xc2\xb0。我尝试了textangle关键字,但不起作用。
trace = go.Scatter(\n x=[1999],\n y=[1],\n mode='text',\n name='Note',\n text=['Missing data due to database change'],\n textposition='middle center'\n)\nRun Code Online (Sandbox Code Playgroud)\n plotly ×10
python ×6
r ×3
plotly-dash ×2
gantt-chart ×1
ggplot2 ×1
ggplotly ×1
python-3.x ×1
r-plotly ×1
violin-plot ×1