plotly / plotly/plotly.py

Transparent markers misbehaving in plotly.express.scatter

未關閉
#4,664 5 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

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

描述

Description

I create a scatter plot and use the color and size arguments. One subset gets transparent markers and is not visible in the plot and the legend.

But: if I hover over an area, where a marker should be, the tool tip is appearing, see figure below:

image

Expected Behavior

Marker should be visible in plot and legend.

Reproduction

Running the code below I get the figure above.

# %%
# Imports

import sys
import plotly
import pandas as pd
import plotly.express as px

print(f'Python version: {sys.version}')  # Mine is: 3.11.9
print(f'Pandas version: {pd.__version__}')  # Mine is: 2.2.2
print(f'Plotly version: {plotly.__version__}')  # Mine is: 5.22.0

# %%
# Create input frame

df = pd.DataFrame(
  [
    [11739,21.329416,10.010795,2,1],
    [20500,21.860714,12.238669,2,2],
    [1504,21.927166,10.314574,2,1],
    [28194,21.257576,12.823945,2,3],
    [9008,21.886381,9.579169,2,1],
    [17073,21.57327,11.087076,2,1],
    [40734,21.069445,11.887547,3,0],
    [36405,22.397081,11.608735,3,0],
    [36919,21.95463,12.856195,3,0],
    [9867,20.893126,10.761697,2,1]
  ],
  columns=['id' ,'x', 'y', 'loop_number', 'repetition']
)

df.set_index('id', inplace=True)

df.x = df.x.astype('float32')
df.y = df.y.astype('float32')
df.loop_number = df.loop_number.astype('category')  # As category to use color labels, not a color bar.
df.repetition = df.repetition.astype('int32')

df.head()

# %%
# Create Scatter Plot

px.scatter(
  df,
  x='x',
  y='y',
  color='loop_number',
  size='repetition',
  labels={
    'color': 'Type',
    'size': 'Size'
  },
  hover_name=df.index
)

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

使用 color='loop_number' 和 size='repetition',透過 plotly.express.scatter 執行提供的 Python 重現程式。檢查為什麼透明子集雖然仍可透過 hover 查看,卻同時被從圖表和圖例中省略;當該子集的標記和圖例項目可見,同時保留所回報的 scatter 行為時,即視為完成。

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

評估

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

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

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