标签: plotly

ModuleNotFoundError:没有名为“plotly”的模块

在阅读了与此问题相关的所有现有帖子后,我仍然无法解决它。

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)

python python-3.x plotly

5
推荐指数
1
解决办法
2万
查看次数

返回数字字典时回调返回值无效

我试图返回一个条形图,但用于条形图的列根据下拉值选择而变化。我将字典返回到 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)

python plotly plotly-dash

5
推荐指数
1
解决办法
6781
查看次数

强制小提琴图不显示零值上的小提琴

我有几个组的测量值,我想将它们绘制为小提琴图:

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?

r plotly violin-plot

5
推荐指数
1
解决办法
1543
查看次数

Plotly - 如何制作没有盒子的箱线图?

我试图在 python 中使用plotly来创建箱线图,但我只想要点,而不是盒子、晶须或其他任何东西。像这样的东西: 在此输入图像描述

找不到办法做到这一点。我能做的最好的就是 set ,但这只显示框 之外的boxpoints='all'点:在此输入图像描述

这可能吗?有解决方法的想法吗?

python plotly plotly-python

5
推荐指数
1
解决办法
5742
查看次数

在绘图中设置长文本标签的工具提示格式

考虑下面的简单示例。有没有一种方法可以格式化绘图工具提示,以便长文本标签在框中可见,而不是这个截断值的荒谬矩形?

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)

在此输入图像描述

r ggplot2 plotly ggplotly

5
推荐指数
1
解决办法
1914
查看次数

Plotly:如何在甘特图上标记条形?

有没有什么方法可以在 Plotly 甘特图中创建任务标签在条形图上和资源标签在 y 轴上?

的文档中没有这样的例子plotly.figure_factory.create_gantt。下面给出了理想图表的抽象示例:

在此输入图像描述

python visualization gantt-chart plotly

5
推荐指数
1
解决办法
9394
查看次数

如何按组为散点图分配颜色?

我正在尝试为数据框中的每个类分配颜色,这是我的代码:

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)

所以问题是它没有根据 …

python plotly plotly-python

5
推荐指数
2
解决办法
2万
查看次数

如何从可编辑表格更新绘图/虚线图?

我有一个带有可删除行和列的破折号 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-dash

5
推荐指数
1
解决办法
5174
查看次数

更改绘图悬停框 R 的位置

我想更改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)

r plotly r-plotly

5
推荐指数
0
解决办法
747
查看次数

如何在绘图轨迹中旋转文本?

以下跟踪在绘图中显示了一些文本。我想将此文本旋转到 90\xc2\xb0。我尝试了textangle关键字,但不起作用。

\n\n
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)\n
Run Code Online (Sandbox Code Playgroud)\n

python plotly

5
推荐指数
1
解决办法
3067
查看次数