_覓 | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁 |
FrontPage › Python-ScatterPlot
|
|
[edit]
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>: 蠍郁讌 覯 ろ [edit]
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) [edit]
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
鏤
|
襷襦 豌 豺殊 襷 豌覲企 . |