Python-IDE Jupiter Notebookを使用して、棒グラフの1つの特定の棒の色を変更するにはどうすればよいですか。

ディラン・ヴァゲラ

私のコードは現在これです-私が作成した日付セットを使用しています!

    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    import os

    desired_width=420
    pd.set_option('display.width', desired_width)
    np.set_printoptions(linewidth=desired_width)
    pd.set_option('display.max_columns',6)

    Data = pd.read_csv("/Volumes/DYLAN USB/Excel/DataSheets/Data Passing Feb EPL 202021.csv",index_col=0)

print(Data.head(20))

    fig, ax = plt.subplots()
    Data = Data.sort_values('Total Pass Completion %', ascending=False)
    ax.bar(Data.Team, Data['Total Pass Completion %'])
    ax.set_xticklabels (Data.Team, rotation=90, horizontalalignment = 'right', fontsize = '12')

   ax.set_title ('League Ranking and Points- EPL 2020/21 February', fontsize =22)
   ax.set_ylabel ('Pass Completition %')
   ax.set_xlabel ('Team Name')
ウィリアム・グッドウィン

人々に質問を簡単に解決してもらいたい場合は、サンプルデータを提供する必要があります。以下にいくつかのデータを作成しました。バーオブジェクトにインデックスをmatplotlib.patches.Rectangle付けて、必要な色に設定できます

import pandas as pd 
import matplotlib.pyplot as plt 

Data = pd.DataFrame({'Total Pass Completion %': [100, 30, 8, 4], 'Team': ['A', 'B', 'C', 'D']})

fig, ax = plt.subplots()
Data = Data.sort_values('Total Pass Completion %', ascending=False)
ax.bar(Data.Team, Data['Total Pass Completion %'])
ax.set_xticklabels (Data.Team, rotation=90, horizontalalignment = 'right', fontsize = '12')

ax.set_title ('League Ranking and Points- EPL 2020/21 February', fontsize =22)
ax.set_ylabel ('Pass Completition %')
ax.set_xlabel ('Team Name')


ax.get_children()[1].set_color('r')

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ