<jupyter_start><jupyter_text>quero usar matplotlib para ilustrar permutaçõesA primeira coisa é fazer circulos numerados<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np 
circle1=plt.Circle((0,0),.1,color='r', alpha=0.2, clip_on=False)
plt.axes(aspect="equal")
fig = plt.gcf()
fig.gca().add_artist(circle1)
plt.axis("off")
circle1=plt.Circle((0,0),.1,color='r', alpha=0.2, clip_on=False)
circle2=plt.Circle((0,0.2),.1,color='y', alpha=0.2, clip_on=False)
circle3=plt.Circle((0,0.4),.1,color='b', alpha=0.2, clip_on=False)
circle4=plt.Circle((0,0.6),.1,color='g', alpha=0.2, clip_on=False)
circle5=plt.Circle((0,0.8),.1,color=(0.2,0.6,0.7), alpha=0.2, clip_on=False)
plt.axes(aspect="equal")
fig1 = plt.gcf()
plt.axis("off")
fig1.gca().add_artist(circle1)
fig1.gca().add_artist(circle2)
fig1.gca().add_artist(circle3)
fig1.gca().add_artist(circle4)
fig1.gca().add_artist(circle5)
circle1=plt.Circle((0,0),.1,color='r', alpha=0.2, clip_on=False)
circle2=plt.Circle((0,0.2),.1,color='y', alpha=0.2, clip_on=False)
circle3=plt.Circle((0,0.4),.1,color='b', alpha=0.2, clip_on=False)
circle4=plt.Circle((0,0.6),.1,color='g', alpha=0.2, clip_on=False)
circle5=plt.Circle((0,0.8),.1,color=(0.2,0.6,0.7), alpha=0.2, clip_on=False)
circled1=plt.Circle((1,0),.1,color='r', alpha=0.2, clip_on=False)
circled2=plt.Circle((1,0.2),.1,color='y', alpha=0.2, clip_on=False)
circled3=plt.Circle((1,0.4),.1,color='b', alpha=0.2, clip_on=False)
circled4=plt.Circle((1,0.6),.1,color='g', alpha=0.2, clip_on=False)
circled5=plt.Circle((1,0.8),.1,color=(0.2,0.6,0.7), alpha=0.2, clip_on=False)
plt.axes(aspect="equal")
fig1 = plt.gcf()
plt.axis("off")
fig1.gca().add_artist(circle1)
fig1.gca().add_artist(circle2)
fig1.gca().add_artist(circle3)
fig1.gca().add_artist(circle4)
fig1.gca().add_artist(circle5)
fig1.gca().add_artist(circled1)
fig1.gca().add_artist(circled2)
fig1.gca().add_artist(circled3)
fig1.gca().add_artist(circled4)
fig1.gca().add_artist(circled5)
circle1=plt.Circle((0,0),.1,color='r', alpha=0.2, clip_on=False)
circle2=plt.Circle((0,0.2),.1,color='y', alpha=0.2, clip_on=False)
circle3=plt.Circle((0,0.4),.1,color='b', alpha=0.2, clip_on=False)
circle4=plt.Circle((0,0.6),.1,color='g', alpha=0.2, clip_on=False)
circle5=plt.Circle((0,0.8),.1,color=(0.2,0.6,0.7), alpha=0.2, clip_on=False)
circled1=plt.Circle((1,0),.1,color='r', alpha=0.2, clip_on=False)
circled2=plt.Circle((1,0.2),.1,color='y', alpha=0.2, clip_on=False)
circled3=plt.Circle((1,0.4),.1,color='b', alpha=0.2, clip_on=False)
circled4=plt.Circle((1,0.6),.1,color='g', alpha=0.2, clip_on=False)
circled5=plt.Circle((1,0.8),.1,color=(0.2,0.6,0.7), alpha=0.2, clip_on=False)
plt.axes(aspect="equal")
fig1 = plt.gcf()
plt.axis("off")
fig1.gca().add_artist(circle1)
fig1.gca().add_artist(circle2)
fig1.gca().add_artist(circle3)
fig1.gca().add_artist(circle4)
fig1.gca().add_artist(circle5)
fig1.gca().add_artist(circled1)
fig1.gca().add_artist(circled2)
fig1.gca().add_artist(circled3)
fig1.gca().add_artist(circled4)
fig1.gca().add_artist(circled5)
# as arestas
fig1.gca().plot([0.15,0.85],[0,0.8], color="red", alpha=0.6 )
fig1.gca().text(0.,0.,r'$5$', fontsize=20,verticalalignment='center', horizontalalignment='center')
fig1.gca().text(1,0,r'$5$', fontsize=20, verticalalignment='center', horizontalalignment='center')
fig1.gca().text(1,0.8,r'$1$', fontsize=20, verticalalignment='center', horizontalalignment='center')
fig1.gca().text(0,0.8,r'$1$', fontsize=20, verticalalignment='center', horizontalalignment='center')
fig1.gca().plot([0.15,0.85],[0.8,0.4], color=(.2,.6,.7), alpha=0.6 )
# agora faremos as funções. primeiro a cor de um inteiro
def cor(n):
    ''' Dado um inteiro n designa uma cor'''
    return (n/(n+1), 1- n/(n+1), 1-(n+2)/(n+5))
#teste
circle1=plt.Circle((0,0),.1,color=cor(1), alpha=0.2, clip_on=False)
circle2=plt.Circle((0,0.2),.1,color=cor(3), alpha=0.2, clip_on=False)

plt.axes(aspect="equal")
fig1 = plt.gcf()
plt.axis("off")
fig1.gca().add_artist(circle1)
fig1.gca().add_artist(circle2)

def circulo(x,n):
    '''Define um circulo de centro (x,0.2*n) de raio 0.1 e cor n'''
    return plt.Circle((x,0.2*n), .1, color=cor(n), alpha=0.3, clip_on=False )
#teste
plt.axes(aspect="equal")
fig1 = plt.gcf()
plt.axis("off")
fig1.gca().add_artist(circulo(0,3))
fig1.gca().add_artist(circulo(0,4))

# função pilha de circulos
def pilha_de_circulos(x,n):
    '''Faz uma pilha de n circulos sobre a abcissa x'''
    for k in range(n):
        fig1.gca().add_artist(circulo(x,k))
        fig1.gca().text(x,0.2*k,r'$'+str(k+1)+'$', fontsize=20,verticalalignment='center', horizontalalignment='center')
    return
# teste desta função:
plt.axes(aspect="equal")
fig1 = plt.gcf()
plt.axis("off") 
pilha_de_circulos(0,3)
pilha_de_circulos(1,3)
pilha_de_circulos(2,3)
# agora a função mapa_permu
def mapa_permu(x,p):
    ''' desenha a permutação p (uma lista) na posição x'''
    l=len(p)
    x1= x+.15
    x2= x+.85
    for y in range(l):
        fig1.gca().plot([x1,x2],[0.2*y,0.2*(p[y]-1)], color=cor(y), alpha=0.6 )
    return
# teste 
plt.axes(aspect="equal")
fig1 = plt.gcf()
plt.axis("off") 
pilha_de_circulos(0,3)
pilha_de_circulos(1,3)
pilha_de_circulos(2,3)
mapa_permu(0,[2,1,3])
mapa_permu(1.0, [3,1,2])
plt.axes(aspect="equal")
fig1 = plt.gcf()
plt.axis("off") 
pilha_de_circulos(0,5)
pilha_de_circulos(1,5)
mapa_permu(0,[3,2,1,5,4])
def pgrafico(x,p):
    '''Faz o grafico da permutação p começando em x'''
    n=len(p)
    fig1= plt.gcf()
    plt.axis("off")
    pilha_de_circulos(x,n)
    pilha_de_circulos(x+1,n)
    return mapa_permu(x,p) 
#teste
plt.axes(aspect="equal")
fig1= plt.gcf()
plt.axis("off")
pgrafico(0,[3,1,2])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.23089115885875308, 'fraction_numerical': 0.07396970764353646, 'mean_word_length': 6.726530612244898, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '12911', 'license': 'CC0-1.0', 'n_tokens_mistral': 2843, 'n_tokens_neox': 2733, 'n_words': 334, 'path': 'matplotlibteste.ipynb', 'repo_name': 'patonelli/map2110-modelagem', 'size': '5678'}