_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › Python-ScatterPlot

Contents

1 scatter plot: matplotlib
2 scatter plot: seaborn
3 R pairs 蠏碁


1 scatter plot: matplotlib #

#two_moon 一危 
from sklearn.datasets import make_moons
import pandas as pd
X, y = make_moons(n_samples=200, noise=0.05, random_state=0)

df = pd.DataFrame(X, columns=["x", "y"])
df["group"] = y
df[:5]

import matplotlib.pyplot as plt
plt.scatter(x=df.x, y=df.y, c=df.group)

貉襯 讌伎手 苦朱
#<scatter plot>: 蠍磯
import matplotlib.pyplot as plt
plt.scatter(x=df.x, y=df.y, c=df.group)

fig, ax = plt.subplots()
colors = {1:'red', 0:'blue'}

grouped = df.groupby('group')
for key, group in grouped:
    group.plot(ax=ax, kind='scatter', x='x', y='y', label=key, color=colors[key])
plt.show()
#</scatter plot>: 蠍郁讌 覯 ろ

2 scatter plot: seaborn #

#iris 一危一誤 襷り鍵
import numpy as np
import pandas as pd
from sklearn.datasets import load_iris
iris = load_iris()
iris.data
iris.feature_names
iris.target
iris.target_names


iris_df = pd.DataFrame(iris.data, columns=iris.feature_names)
iris_df["target"] = iris.target 
iris_df["target_names"] = iris.target_names[iris.target]

#scatter plot
import seaborn as sns
sns.pairplot(x_vars=["sepal length (cm)"], y_vars=["petal length (cm)"], data=iris_df, hue="target_names", size=5)

3 R pairs 蠏碁 #

#iris 一危一誤 襷り鍵
import pandas as pd
from sklearn.datasets import load_iris

iris = load_iris()
iris.data
iris.feature_names
iris.target
iris.target_names


iris_df = pd.DataFrame(iris.data, columns=iris.feature_names)
iris_df["target"] = iris.target 
iris_df["target_names"] = iris.target_names[iris.target]

#scatter plot
import mglearn
pd.tools.plotting.scatter_matrix(iris_df, c=iris_df.target, 
                                 figsize=(15,15), marker="o", 
                                 hist_kwds={"bins":20},s=60, alpha=0.8, cmap=mglearn.cm3)

#s: marker 蠍
#cmap: color map

scatter_plot.png
蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:52

讌 覈 覿 朱 讌 覈詩螻 . 蠏碁覩襦 磯る 蟆 る . ( )