4
a=pd.DataFrame({'length':[20,10,30,40,50],
                'width':[5,10,15,20,25],
                'height':[7,14,21,28,35]})

for i,feature in enumerate(a,1):
    sns.regplot(x = feature,y= 'height',data = a)
    print("{} plotting {} ".format(i,feature))

I want to plot 3 different plots with three different columns i.e 'length','width' and 'height' on x-axis and 'height' on y-axis in each one of them .
This is the code i wrote but it overlays 3 different plots over one another.I intend to plot 3 different plots.

1
  • Your question is asking how to write the code. Ask a more generalized question. and put more details such as which programming language, what are you trying to achieve? what is the logic you have used? Ask whether certain logic will work? If you put a code and ask for debugging, you wont find answers :) Commented Nov 27, 2019 at 8:53

1 Answer 1

5

It depends on what you want to do. It you want several individual plots, you can create a new figure for each dataset:

import matplotlib.pyplot as plt
for i, feature in enumerate(a, 1):
    plt.figure()  # forces a new figure
    sns.regplot(data=a, x=feature, y='height')
    print("{} plotting {} ".format(i,feature))

Alternatively, you can draw them all on the same figure, but in different subplots. I.E next to each other:

import matplotlib.pyplot as plt
# create a figure with 3 subplots
fig, axes = plt.subplots(1, a.shape[1])
for i, (feature, ax) in enumerate(zip(a, axes), 1):
    sns.regplot(data=a, x=feature, y='height', ax=ax)
    print("{} plotting {} ".format(i,feature))

3 plots next to each other

plt.subplots has several options that allow you to align the plots the way you like. check the docs for more on that!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.