Colors 使用Seaborn stripplot中的一系列值设置色调
我试图在seaborn stripplot中根据一系列值而不是唯一值设置色调。例如,不同值范围的不同颜色(1940-1950、1950-1960等)Colors 使用Seaborn stripplot中的一系列值设置色调,colors,range,seaborn,Colors,Range,Seaborn,我试图在seaborn stripplot中根据一系列值而不是唯一值设置色调。例如,不同值范围的不同颜色(1940-1950、1950-1960等) 谢谢看起来您需要将数据放入垃圾箱。按以下方式使用。年份分为5组。您可以在中安排自己的步骤来调整范围 import pandas as pd import numpy as np import seaborn as sns import matplotlib.pyplot as plt x = np.random.randint(0,100,si
谢谢看起来您需要将数据放入垃圾箱。按以下方式使用。年份分为5组。您可以在中安排自己的
步骤来调整范围
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
x = np.random.randint(0,100,size=100)
y = np.random.randint(0,100, size=100)
year = np.random.randint(1918, 2019, size=100)
df = pd.DataFrame({
'x':x,
'y':y,
'year':year
})
df['year_bin'] = pd.cut(df['year'], np.arange(min(year), max(year), step=20))
sns.lmplot('x','y', data=df, hue='year_bin')
plt.show()
输出:
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
x = np.random.randint(0,100,size=100)
y = np.random.randint(0,100, size=100)
year = np.random.randint(1918, 2019, size=100)
df = pd.DataFrame({
'x':x,
'y':y,
'year':year
})
df['year_bin'] = pd.cut(df['year'], np.arange(min(year), max(year), step=20))
sns.lmplot('x','y', data=df, hue='year_bin')
plt.show()