Make 1 figure with 3 graphs

Asked

Viewed 955 times

2

I have 3 functions like the following that allows to obtain each one a graph and I want a function where use the 3 graphs of the other functions to join in one figure.

def funcao1(grafico):
    ...
    pylab.plot(range(len(x)), y)
    pylab.xticks(z,sorted(set(x)))
    pylab.title("crimes")
    pylab.xlabel("Anos")
    pylab.ylabel("# Crimes")
    pylab.show()

def funcao2(grafico):
    ...
    pylab.plot(range(len(y)), x)
    pylab.xticks(b,sorted(set(y)))
    pylab.title("nomes")
    pylab.xlabel("Anos")
    pylab.ylabel("# Crimes")
    pylab.show()

def funcao3(grafico):
    ...
    pylab.plot(range(len(a)), e)
    pylab.xticks(p,sorted(set(a)))
    pylab.title("idades")
    pylab.xlabel("Anos")
    pylab.ylabel("# Crimes")
    pylab.show()

def quatro_figuras(grafico):

      #Aqui obter uma figura com os 3 graficos

1 answer

2


I think you should use the subplot command, if I’m not mistaken the code should look like this:

y = [1,2,3]
x = [5,6,7]

def funcao1(): 
    pylab.subplot(221)
    pylab.title("crimes")
    pylab.xlabel("Anos")
    pylab.ylabel("# Crimes")
    pylab.plot(range(len(x)), y)

def funcao2():
    pylab.subplot(222)
    pylab.title("nomes")
    pylab.xlabel("Anos")
    pylab.ylabel("# Crimes")
    pylab.plot(range(len(x)), y)

def funcao3():
    pylab.subplot(223)
    pylab.title("idades")
    pylab.xlabel("Anos")
    pylab.ylabel("# Crimes")
    pylab.plot(range(len(x)), y)

def quatro_figuras():
    pylab.show()

funcao1()
funcao2()
funcao3()
quatro_figuras()

Since the first digit corresponds to the number of lines of graphics, the 2nd the number of columns and the 3rd corresponds to the number of each graph. An example can be seen here.

Change the example according to your work.

  • It’s not working right , when I do it it does " None "

  • 1

    @user44708 on which line?

  • For example when I run the function " quatro_figures" with F5 , it appears " None " it does nothing

  • @user44708 before running this function you evoke functions 1, 2 and 3?

  • That’s right, thank you :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.