0

What I want:
I want to plot around 8 density(violin) plots(all in separate graphs) using a function, however when I run I get either a single plot with all 8 features or 8 different plots of the same feature.
How to plot different plots on different graphs using a function?

My current codes:

#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))
ultron
  • 442
  • 8
  • 16
  • you mean something like this https://seaborn.pydata.org/_images/faceted_histogram.png – Eliethesaiyan Apr 11 '17 at 07:06
  • @Eliethesaiyan no I'm not faceting a same variable with different factors.what i'm trying to do is to visualise 8 different columns of a dataset with a function, all plots should be different. – ultron Apr 11 '17 at 07:09
  • what are you getting in with the code you provided? – Eliethesaiyan Apr 11 '17 at 07:12
  • code-1 gives me 8 plots(all exactly the same, on only one column), code-2 produces 1 plot with all columns density visualised together. – ultron Apr 11 '17 at 07:19
  • i see....i think what you are looking for is subplots i am not familiar with it but this answer might help http://stackoverflow.com/questions/33925494/seaborn-produces-separate-figures-in-subplots – Eliethesaiyan Apr 11 '17 at 07:26
  • You cannot ask a question like *"why is `some_fancy_function` not doing what I'd like it to do?"* without providing the details of `some_fancy_function`! – ImportanceOfBeingErnest Apr 11 '17 at 08:19

1 Answers1

1

Without knowing anything about visualise_univariate_feature it's impossible to give a definitive answer.

However you might try

for i, feature in enumerate(features):
    plt.figure(i+1)
    display(visualise_univariate_feature(x=feature))
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712