plotly / plotly/plotly.py

go.images moved around dcc.graph in combination with plotly.make_subplots()

未關閉
#3,985 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

bug P3
主要語言
Python
星號
18.8k
分支
2.8k
平均合併
16 小時 26 分鐘
30 天內合併 PR
21

描述

First off, I have also addressed this in the plotly community website, but I feel like this is the place it should be posted.

EDIT: I realize it might be better suited in the dash github. Let me know if I need to move it.

There is a bug in plotly when using dcc.Graph in combination with a subplot figure consisting of go.Images the go.Images get moved around after the user changes the number of rows of plotly.make_subplots().
For example, when I first choose to plot 5 images beneath each other, the plot will look fine, plotting five images closely together (chosen first). However, when the user subsequently chooses to plot 2 points, the images will be plotted in the same space the five images were. Similarly, when the user first chooses to plot 2 images the image looks fine. Subsequently, when the user plots 5 images, they all get messed up.

This does not happen when plotting, for example, scatter plots. Moreover, adding subtitles to the plot shows that the subtitles do not get moved around either. Using fig.show() on the figures also gives a good figure.

You can use the code below to get a minimal working example.
Moreover, using fig.show() also shows the images in their correct spaces. I believe this is a problem with dcc.graph in combination with subplots using go.Image.

from dash import Dash, dcc, html
from dash.dependencies import Input, Output
import plotly.graph_objects as go
import dash.exceptions
import numpy as np
from plotly.subplots import make_subplots
import plotly.express as px

def create_fig(n_rows):
    fig = make_subplots(n_rows, 1)

    for i in range(n_rows):
        fig.add_trace(go.Image(z=np.random.randint(0, 255, size=(60, 60, 3))), i+1, 1)
        #fig.add_trace(go.Scatter(x=[1, 2], y=[2, 4]), i + 1, 1)

    fig.update_layout(autosize=True,
                      width=100,
                      height=n_rows*100,
                      margin=dict(l=0, r=0, b=0, t=0)
                      )
    print(fig.layout)
    return fig


app = Dash(__name__)
app.layout = html.Div(
    [dcc.Graph(id='graph', style={'overflow':'scroll'}),
     dcc.Input(value=0, id='input', type='number')])


@app.callback(Output('graph', 'figure'), Input('input', 'value'))
def create_graph(n_rows):
    if n_rows == 0:
        raise dash.exceptions.PreventUpdate("Prevent update")
    else:
        if n_rows is not None:
            return create_fig(int(n_rows))


if __name__ == '__main__':
    app.run_server(debug=True)

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先執行最小的 Dash 範例,重點關注 dcc.Graph callback、create_fig、make_subplots 和 go.Image traces,同時將輸入列數在兩列和五列之間切換。將更新後的 figure 與 fig.show() 以及 scatter 和 subtitle 情況進行比較。完成的標準是列數變更後,影像仍保留在正確的 subplot 空間中。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
numpy, python
領域
data-visualization, frontend
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。