我正在尝试绘制水平条形图。可以,但是颜色是彩虹风格。如何将每个条形的颜色更改为相同的颜色?
%pyspark
import seaborn as sns
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
plt.clf()
sns.set_context("notebook", font_scale=0.5)
# plot barchart by x axis and use different color for day
sns.barplot(x = "scaled_importance",
y = "variable",
data = best_gbm_varimp[:10],
orient = "h")
show(plt)
答案 0 :(得分:0)
您可以使用参数:seaborn.barplot
color: matplotlib color, optional
Color for all of the elements, or seed for a gradient palette.
用于可视化示例示例:Horizontal bar plots
下面是一个没有颜色的示例,因此结果为“彩虹”:
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
# Initialize the matplotlib figure
f, ax = plt.subplots(figsize=(6, 15))
# Load the example car crash dataset
crashes = sns.load_dataset("car_crashes").sort_values("total", ascending=False)
# Plot the crashes where alcohol was involved
sns.set_color_codes("muted")
sns.barplot(x="alcohol", y="abbrev",
data=crashes,
label="Alcohol-involved",
orient = "h")
现在,我们指定 color ='b' #blue:
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
# Initialize the matplotlib figure
f, ax = plt.subplots(figsize=(6, 15))
# Load the example car crash dataset
crashes = sns.load_dataset("car_crashes").sort_values("total", ascending=False)
# Plot the crashes where alcohol was involved
sns.set_color_codes("muted")
sns.barplot(x="alcohol", y="abbrev",
data=crashes,
label="Alcohol-involved",
orient = "h",
color='b')