アイリスデータセットを分析し、花びらの幅と長さの間に散布図を作成しました。プロットを作成するために、私はこのコードを使用しました:
# First, we'll import pandas, a data processing and CSV file I/O library
import pandas as pd
# We'll also import seaborn, a Python graphing library
import warnings # current version of seaborn generates a bunch of warnings that we'll ignore
warnings.filterwarnings("ignore")
import seaborn as sns
import matplotlib.pyplot as plt
import numpy
sns.set(style="dark", color_codes=True)
# Next, we'll load the Iris flower dataset, which is in the "../input/" directory
iris = pd.read_csv("Iris.csv") # the iris dataset is now a Pandas DataFrame
# Let's see what's in the iris data - Jupyter notebooks print the result of the last thing you do
print(iris.head(10))
# Press shift+enter to execute this cell
sns.FacetGrid(iris, hue="Species", size=10) \
.map(plt.scatter, "PetalLengthCm", "PetalWidthCm") \
.add_legend()
その後、回帰直線をプロットしましたが、この直線をプロットした後、色がよく見えません。回帰直線の色を変更しようとしましたが、効果がありませんでした。異なる種の色を失うことなく回帰直線をプロットするにはどうすればよいですか?
回帰直線を含むプロットを作成するためのコードは次のとおりです。
sns.FacetGrid(iris, hue="Species", size=10) \
.map(plt.scatter, "PetalLengthCm", "PetalWidthCm") \
.add_legend()
sns.regplot(x="PetalLengthCm", y="PetalWidthCm", data=iris)
petal_length_array = iris["PetalLengthCm"]
petal_width_array = iris["PetalWidthCm"]
r_petal = numpy.corrcoef(petal_length_array, petal_width_array) # bereken de correlatie
print ("Correlation is : " + str(r_petal[0][1]))
あなたの問題はsns.regplot()
、異なる色のポイントの上に、すべてのポイントを同じ色で描画することです。
これを回避するには、呼び出しregplot(..., scatter=False)
て個々のデータポイントがプロットされないようにしてください。のドキュメントを確認してくださいregplot
。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加