标签: plotly

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

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

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
查看次数

在Python中绘制带有图例的垂直线

在plotly网站中,有一个示例可以使用shape函数在plotly中添加垂直或水平线。

import plotly.plotly as py
import plotly.graph_objs as go

trace0 = go.Scatter(
    x=[2, 3.5, 6],
    y=[1, 1.5, 1],
    mode='text',
)
data = [trace0]
layout = {
    'xaxis': {
        'range': [0, 7]
    },
    'yaxis': {
        'range': [0, 2.5]
    },
    'shapes': [
        # Line Horizontal
        {
            'type': 'line',
            'x0': 2,
            'y0': 2,
            'x1': 5,
            'y1': 2,
            'line': {
                'color': 'rgb(50, 171, 96)',
                'width': 4,
                'dash': 'dashdot',
            }
        }
    ]
}

fig = {
    'data': data,
    'layout': layout,
}

py.iplot(fig, filename='shapes-lines') …
Run Code Online (Sandbox Code Playgroud)

python python-3.x plotly

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

django-plotly-dash div 尺寸太小并且不会改变

使用 Django-plotly-dash 模块和 dash 应用程序在一个非常小的窗口中渲染。除了典型的 css 之外,我还能做些什么来渲染这个完整的页面吗?

我尝试过更新特定 div 的样式以及更新整个页面中的样式。

...

{% extends 'base_page.html' %}
{% block content %}
<head>

</head>
<body>
{%load plotly_dash%}

    <div class={% plotly_class name="SimpleExample"%}>

        {% plotly_app name="SimpleExample" %}
      </div>
</body>
{% endblock %}
...
Run Code Online (Sandbox Code Playgroud)

期望 div 是整页,但它只呈现一个非常小的窗口

css django plotly plotly-dash

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

阴谋。不同桑基图之间节点大小的缩放比例不同

我正在Python中使用plotly绘制桑基图,如下所示:https://plot.ly/~alishobeiri/1591/plotly-sankey-diagrams/#/。

对于单个桑基图,节点的大小会缩放,以便它们填充整个图的高度。在比较不同的 sankey 时,这是一个问题,因为它们的缩放比例不同。有没有办法根据某个值缩放节点的高度,然后可以在所有桑基绘图中使用它。Fx,1000对应1cm。最后,人们将能够仅通过查看大小来比较不同图中的桑基节点,而不考虑实际的节点值。

python alignment plotly sankey-diagram

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

Plotly Python 中的刻度格式

我正在尝试将 Plotly 条形图 x 轴格式设置为带有 3 位小数的百分比。

import chart_studio.plotly as py #for plotting
import plotly.graph_objs as go


y = ['niner', 'deuce', 'checker']
x = [0.03, -0.05, 0.075]


fig = go.Figure(go.Bar(y = y, x = x,
            name = 'returns',
            orientation = 'h',
            marker = dict(color = '#003663',
                             line = dict(
                                      color = '#afafaf',
                                      width = 1.5)
                                    )))

fig.update_layout(
        title = 'Why So Hard Plotly?',
        xaxis = dict(
                tickformat = '%.format.%3f',
                title = 'Returns',
                fixedrange = True,
                hoverformat = '.3f',
                showgrid = …
Run Code Online (Sandbox Code Playgroud)

python python-3.x plotly plotly.js plotly-python

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

传说中的顺序情节

就像这里提出的类似问题一样,我想更改绘图饼图图例的顺序。不同之处在于,我不能简单地使用traceorder,因为我有超过 6 个标签,并且颠倒它们并不会将它们按正确的顺序排列。

有没有办法自定义订单?

以 4 个标签为例:

import plotly.offline as py
trace1 = go.Pie(                    
    values = [2, 4, 4, 9],                    
    labels = ['A', 'B', 'C', 'D'],
    name    = "Succes" 
)

data = [trace1]
fig  = go.Figure(data = data)
py.plot(fig)
Run Code Online (Sandbox Code Playgroud)

目前情况如何

我想预先指定图例的顺序。

python plotly

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

如何制作绘图图形对象的副本?

如何复制绘图图形对象以进行一些更改,但为其他绘图保留相同的基本结构?

以下引发属性错误:

代码:

fig2=fig1.copy()
Run Code Online (Sandbox Code Playgroud)

错误:

属性错误:“图形”对象没有属性“复制”

当然fig2=fig1不会有帮助,因为两个名称将指向同一个对象。

python plotly plotly-python

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