Précédent   Forum des professionnels en informatique > Autres langages > Python & Zope > Calcul scientifique
Calcul scientifique Forum d'entraide sur la programmation scientifique et bibliothèques associées (PIL, NumPy, SciPy, ...)
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 10/12/2011, 03h03   #1
 
Femme gaelle djomo
bac1 en informatique
Inscription : novembre 2011
Messages : 2
Détails du profil
Informations personnelles :
Nom : Femme gaelle djomo
Localisation : Belgique

Informations professionnelles :
Activité : bac1 en informatique
Secteur : Enseignement

Informations forums :
Inscription : novembre 2011
Messages : 2
Points : -1
Points : -1
Par défaut comment nommer les axes et ajouter des valeurs à tick_size(taille d'un tick)

Je veux décorer le graphique :
– Nommer les axes (x et y) ;
– Ajouter les flèches aux axes (pensez à utiliser la fonction drawLine) ;
– Ajouter les valeurs sur les ticks.
J'arrive à le faire en utilisant numpy hors dans mon travail il faut pas;Voici mon code:
Et aussi
Ma fonction plot(range_x, range_y, step, func) dessine une fonction mathématique sur un plan centré en (0; 0). Je veux ajouter
la possibilité de centrer le dessin sur n’importe quelle autre coordonnée. En ajoutant 2 paramètres à la fonction plot : center_x et center_y. Ces paramètres doivent avoir des valeurs par défaut (0, 0).
Les paramètres center_x et center_y sont des coordonnées, c’est-à-dire que si center_x=3 et
center_y=-5 alors le point (3, -5) doit se trouver au centre de l’image en sortie.

J'ai créé un autre fichier dans lequel j'ai mis argparse, le module qui me permet de creer et d'appeller tous mes arguments("le voici:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import argparse 
from PPMMgr import *
from FctMgr import *
from config import *
 
parser = argparse.ArgumentParser(description='argparse')
parser.add_argument('-o', '--output', help='fichier de sortie', type='str', default='out.ppm')
parser.add_argument('-s', '--step', action='store',help='pas', type=float, default='0.1')
parser.add_argument('--xrange', metavar='range_x', action='store',help='intervalle horizontal', type=int, default='10')
parser.add_argument('--yrange', metavar='range_y', action='store', help='intervalle vertical', type=int, default='10')
parser.add_argument('--xcenter', metavar='center_x', action='store', help='centre horizontal', type=float, default='0')
parser.add_argument('--ycenter', metavar='center_y', action='store', help='centre vertical', type=int, default='0')
parser.add_argument('function', metavar='function', type=str, nargs='+', help='liste de fonctions')
 
 
args = parser.parse_args()
##association des variables définies à leur argument####################
range_x = args.xrange
range_y = args.yrange
step = args.step
filename=args.output
center_x = args.xcenter
center_y = args.ycenter
func = args.function
 
## sauvegarde du resultat dans le fichier 'filename'########################
matrixToFile(M, filename)  ) 
 
jusque au cas où
 
 
from math import *
from config import *
 
def plot(range_x, range_y, step, function, center_x, center_y):
	range_x = float(range_x)/2
	range_y = float(range_y)/2
	step = float(step)
	center_x = center_x*TICK_SIZE
	center_y = center_y*TICK_SIZE
 
	## créer la matrice avec les dimensions HEIGHT et WIDTH
	M = [ [BG for y_i in range(HEIGHT)] for x_i in range(WIDTH)]
 
	## dessiner les axes
	drawAxes(M, range_x, range_y, AXIS_COLOR)
 
	m=0
	while n<m:
		color[n] = function[m]
		drawFunction(M, range_x, range_y, function[m], step, color[n])
		m+=1
 
	## dessiner la fonction passée en paramètre
	drawFunction(M, range_x, range_y, function, step, color)
 
	print "Plotting ", function, "..."
	return M
 
 
 
def xTox_i(x, WIDTH, range_x):
	return int(WIDTH/2 * (x/range_x +1.0))
 
 
def drawAxes(M, range_x, range_y, color):
	# Axes
	drawLine(M, 0, HEIGHT/2, WIDTH-1, HEIGHT/2, color)
	drawLine(M, WIDTH/2, 0, WIDTH/2, HEIGHT-1, color)
 
	# Tics
	for x in range (-1*int(range_x), int(range_x)):
		x_i = xTox_i(x, WIDTH, range_x)
 
		drawLine(M, x_i, HEIGHT/2 - TIC_SIZE, x_i, HEIGHT/2 + TIC_SIZE, color)
 
	for y in range (-1*int(range_y), int(range_y)):
		y_i = xTox_i(y, HEIGHT, range_y)
		drawLine(M, WIDTH/2 - TIC_SIZE, y_i, WIDTH/2 + TIC_SIZE, y_i, color)
 
 
def drawFunction(M, range_x, range_y, function, step, color):
	x = -range_x
	x_old = y_old = None
 
	while x <= range_x*1.01 :
			y = eval(function)
			# déterminer les points x_i et y_i
			x_i = xTox_i(x, WIDTH, range_x) 
			y_i = xTox_i(-y, HEIGHT, range_y)
			# dessiner une ligne entre (x_old,y_old) et (x_i,y_i)
			if x_old != None :
				drawLine(M, x_old, y_old, x_i, y_i, color)
 
			x_old = x_i
			y_old = y_i
			x += step			
 
 
 
 
def drawLine(M, x_0, y_0, x_1, y_1, color):
	if abs(y_1 - y_0) > abs(x_1 - x_0):
		# la pente est forte
		m = float(x_1-x_0)/(y_1-y_0)
		if y_0 > y_1 :
			y_0, y_1 = y_1, y_0
			x_0, x_1 = x_1, x_0
 
		x_i = x_0
		for y_i in range(y_0, y_1):
			if 0<=x_i<WIDTH and 0<=y_i<HEIGHT :
				M[int(x_i)][y_i] = color
			x_i += m
	else:
		m = float(y_1-y_0)/(x_1-x_0) 
		y_i = y_0
		for x_i in range(x_0, x_1):
			if 0<=x_i<WIDTH and 0<=y_i<HEIGHT :
				M[x_i][int(y_i)] = color
			y_i += m
romigaelle est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 22h26.


 
 
 
 
Partenaires

Hébergement Web