どのようにパンダのデータフレームの散布図に凡例を追加するには?

sK500:

私は、関心の次の列が含まれているパンダのデータフレームを持っています。

['Relative Width', 'Relative Height', 'Object Name', 'Object ID']

で決定15色で15人のオブジェクト名がありdf.plot(c='Object ID')、その農産物次の図は:

図

私はこれを行う方法を、15オブジェクト名と凡例を表示したいですか?

import matplotlib.pyplot as plt
from annotation_parsers import parse_voc_folder


def visualize_box_relative_sizes(folder_path, voc_conf, cache_file='data_set_labels.csv'):
    frame = parse_voc_folder(folder_path, voc_conf, cache_file)
    title = f'Relative width and height for {frame.shape[0]} boxes.'
    frame.plot(
        kind='scatter',
        x='Relative Width',
        y='Relative Height',
        title=title,
        c='Object ID',
        colormap='gist_rainbow',
        colorbar=False,
    )
    plt.show()

wwnde勧告に基づいて、私は次のようにコードを変更しました:

def visualize_box_relative_sizes(folder_path, voc_conf, cache_file='data_set_labels.csv'):
    frame = parse_voc_folder(folder_path, voc_conf, cache_file)
    title = f'Relative width and height for {frame.shape[0]} boxes.'
    sns.scatterplot(x=frame["Relative Width"], y=frame["Relative Height"], hue=frame["Object Name"])
    plt.title(title)
    plt.show()

これは次のような結果を生成します。

ここでは、画像の説明を入力します。

wwnde:

してみてください

fig, ax = plt.subplots()

ax = sns.scatterplot(x="total_bill", y="tip",
                     hue="size", size="size",
                     data=tips)
ax.set_title('title')
plt.show()

これは、あなたのデフォルトの色の伝説を与える必要があります

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=372940&siteId=1