Partage
  • Partager sur Facebook
  • Partager sur Twitter

Matplotlib python3.2

Blender 2.63

    7 juin 2012 à 12:07:59

    Bonjour,

    j'ai un problème avec un import pour python3.2 dans Blender 2.63.

    J'ai trouvé un fichier d'exemple de fractale que je voudrais ouvrir avec Blender 2.63:

    # MANDELBROT SET
    from numpy import *
    from pylab import *

    # number of iterations
    iterations = 100

    # density of the grid
    density = 1000

    # fractal range
    x_min, x_max = -2, 1
    y_min, y_max = -1.5, 1.5

    # x, y are matrices containing the real and imaginary parts
    # of all z values in the grid
    x, y = meshgrid(linspace(x_min, x_max, density),
    linspace(y_min, y_max, density))

    # we define c as c=x+iy, c is a 1000x1000 matrix
    c = x + 1j*y

    # initially, z=c, we copy so that z and c are different objects in memory
    z = c.copy()

    # m is used to plot the fractal
    m = zeros((density, density))

    # iterations
    for n in xrange(iterations):
    print "Completed %d %%" % (100 * float(n)/iterations)

    # indices of the numbers c such that |z(c)|<=10, with z = z_n
    indices = (abs(z) <= 10)

    # update z
    z[indices] = z[indices]**2 + c[indices]

    # we update the values in m
    m[indices] = n

    # we plot log(m)
    imshow(log(m), cmap=cm.hot,
    extent=(x_min, x_max, y_min, y_max))

    title('Mandelbrot Set')
    xlabel('Re(z)')
    ylabel('Im(z)')
    show()


    Il faut importer Numpy, que j'ai pu installer par:

    apt-get install python3-numpy

    Ensuite il semblerait que pylab, qui dépend de matplotlib, n'existe pas pour python3.

    Je voudrais donc savoir si il existe un équivalent à matplotlib pour python3, ou, tout au moins, comment adapter ce fichier d'exemple pour Blender 2.63, si c'est possible.

    Merci de votre aide.
    • Partager sur Facebook
    • Partager sur Twitter
      7 juin 2012 à 19:26:43

      Bonjour,

      Matplotlib pour Pyhton3 n'existe pas en version officielle ... mais, tu peux aller faire un tour ici
      Le seul hic à ma connaissance est que ça ne soit disponible que sous Windows.
      J'ai travaillé avec cette version sans rencontrer de bugs, mais ... je n'ai pas tout testé !

      Il te reste sinon la solution de repasser sous Python 2.7
      • Partager sur Facebook
      • Partager sur Twitter
        11 juin 2012 à 19:19:37

        Bonjour,

        j'ai trouvé matplotlib pour Linux Ubuntu 12.04 Precise Pangolin.

        Il faut ajouter dans le sources list:

        #matplotlib

        deb http://ppa.launchpad.net/takluyver/mat [...] -daily/ubuntu precise main
        deb-src http://ppa.launchpad.net/takluyver/mat [...] -daily/ubuntu precise main

        deb http://ppa.launchpad.net/takluyver/python3/ubuntu precise main
        deb-src http://ppa.launchpad.net/takluyver/python3/ubuntu precise main

        Ensuite, il faut tout simplement l'installer en apt:

        sudo apt-get install python3-matplotlib

        Mais j'ai aussi trouvé autre chose pour les fractales de très intéressant. Un module nommé Pixel:

        http://www.grappa.univ-lille3.fr/~coul [...] og_pixel.html

        que j'ai installé dans Blender le plus simplement du monde, après avoir ouvert un terminal, je me suis placé dans le dossier scripts de Blender par:

        cd /usr/share/blender/scripts

        ensuite j'ai fait :

        sudo wget http://www.grappa.univ-lille3.fr/~coul [...] oads/pixel.py

        Jusqu'ici, tout va bien. Il passe avec un import pixel dans Blender.

        Donc j'ouvre un éditeur de texte dans Blender, et je met ça:

        import bpy
        from mathutils import *
        from math import *
        import pixel
        
        
        n_max = 500
        x_min = -2.0
        x_max = 1.0
        y_min = -1.0
        y_max = +1.0
        
        
        pixel.initialiser(240, 160, 1)
        pixel.couleur()
        
        def mandelbrot(c):
          
            z = 0.0
            for i in range(n_max):
                z = z * z + c
                if abs(z) > 2.0:
                    return i
        
        def convertir(x, y):
        
            xx = x_min + (x + 0.5) * (x_max - x_min) / pixel.largeur
            yy = y_max + (y + 0.5) * (y_min - y_max) / pixel.hauteur
            return xx, yy
        
        def dessiner():
           
            for x in range(pixel.largeur):
                for y in range(pixel.hauteur):
                    xx, yy = convertir(x, y)
                    n = mandelbrot(complex(xx, yy))
                    if n != None:
                        pixel.marquer(x, y, n * 0.01)
                    else:
                        pixel.marquer(x, y, None)
                pixel.afficher(0)
        
        def zoom(x, y):
           
            global x_min
            global x_max
            global y_min
            global y_max
        
            xx, yy = convertir(x, y)
            dx = 0.25 * (x_max - x_min)
            dy = 0.25 * (y_max - y_min)
            x_min = xx - dx
            x_max = xx + dx
            y_min = yy - dy
            y_max = yy + dy
        
            print("zoom:")
            print("x_min =", x_min)
            print("x_max =", x_max)
            print("y_min =", y_min)
            print("y_max =", y_max)
        
            dessiner()
        
        
        dessiner()
        pixel.sur_clic(zoom)
        pixel.afficher()


        Je fait alt+p, mais le problème est que cela ne s'ouvre pas dans Blender, mais dans une fenêtre externe Python. Moi je voudrais que cela s'ouvre directement dans Blender (forcément sinon quel intérêt ? ^^ ).

        Voilà, donc comment adapter tout ça pour que cela s'ouvre dans Blender directement, si bien sur c'est possible ?

        Merci de votre aide.

        PS: le fichier d'exemple de mon premier message me renvoie une erreur ici dans blender:

        print "Completed %d %%" % (100 * float(n)/iterations)


        Et n'affiche que la fenêtre vide pour le code python dans un terminal.

        Je n'ai pas vraiment cherché à la corriger, je me concentre sur ceux qui semble marcher, mais enfin, au cas où quelqu'un saurait ou ça cafouille, ça éviterait de laisser un fichier foireux traîner.

        À bientôt...
        • Partager sur Facebook
        • Partager sur Twitter

        Matplotlib python3.2

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown