【问题标题】:How to make several plots with seaborn?如何用seaborn制作几个地块?
【发布时间】:2017-04-11 07:03:45
【问题描述】:

我想要什么:
我想使用一个函数绘制大约 8 个密度(小提琴)图(全部在单独的图中),但是当我运行时,我得到一个包含所有 8 个功能的单个图或相同功能的 8 个不同图。
如何使用函数在不同的图表上绘制不同的图?

我目前的代码:

#CODE-1

#feature: a list of 8 features that i want to visualise
#visualise_univariate_feature: a function that plots a seaborn violin plot
#this code produces 8 plots but all on the same feature from the list(the last element of the list)

for i in range(9):
plt.figure(i)
for feature in features:
    display(visualise_univariate_feature(x=feature))

#CODE-2 

#This code produces 1 plot with 8 features all together
for feature in features:
   display(visualise_univariate_feature(x=feature))

【问题讨论】:

  • @Eliethesaiyan 不,我没有面对具有不同因素的同一个变量。我想做的是用函数可视化数据集的 8 个不同列,所有图都应该不同。
  • 你提供的代码有什么用?
  • code-1 给了我 8 个图(全部完全相同,仅在一列上),code-2 产生 1 个图,所有列密度一起可视化。
  • 我明白了....我认为您正在寻找的是我不熟悉的子图,但这个答案可能会有所帮助stackoverflow.com/questions/33925494/…

标签: python matplotlib plot visualization seaborn


【解决方案1】:

如果对visualise_univariate_feature一无所知,就不可能给出明确的答案。

你可以试试

for i, feature in enumerate(features):
    plt.figure(i+1)
    display(visualise_univariate_feature(x=feature))

【讨论】:

  • 谢谢您的建议。你的代码有效!完美的。谢谢。
猜你喜欢
  • 2018-08-03
  • 2019-12-23
  • 2021-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-02
  • 2021-10-01
  • 2020-08-16
相关资源
最近更新 更多