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
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.path
import matplotlib.patches
import matplotlib.pyplot as plt
import math
# Chargement des valeurs
theta_degs=[0,20,50,70,90,110,130] # angles en degrés
rs=[90,100,110,95,96,101,89] # valeurs de rayons
ps=[9,10,11,12,5,14,8] # valeur du point
r_arc=100
# Calcul des coordonnées
xs=[]
ys=[]
for (theta_deg,r) in zip(theta_degs,rs):
theta_rad = np.array(theta_deg)/ 180.0 * np.pi
x=math.cos(theta_rad)*r
xs.append(x)
y=math.sin(theta_rad)*r
ys.append(y)
fig = plt.figure(figsize=(10,10)) # Création de la figure
fig.add_axes((1,1,1,1))
ax = fig.add_subplot(111, aspect='equal') # Création d'un tracé
#---------Affichage des points -------------------------
# Tracé d'une ligne brisée de valeurs
path=matplotlib.path.Path(zip(xs,ys),
codes=[matplotlib.path.Path.MOVETO]+[matplotlib.path.Path.LINETO]*
(len(theta_degs)-1))
patch = matplotlib.patches.PathPatch(path, facecolor='w',edgecolor="k",lw=2)
ax.add_patch(patch)
# Habillage des points
for (x,y,r,theta_deg,p) in zip(xs,ys,rs,theta_degs,ps):
# Affichage du texte des valeurs
ax.text(x-15,y+2,"(r="+str(int(r))+",theta="+str(int(theta_deg))+")")
# Tracé de la ligne de l'axe
path=matplotlib.path.Path(zip([0,x],[0,y]),
codes=[matplotlib.path.Path.MOVETO]+[matplotlib.path.Path.LINETO]*1)
patch = matplotlib.patches.PathPatch(path, facecolor='w',edgecolor="k",linestyle="dashed")
ax.add_patch(patch)
# Tracé du cercle
patch_cercles = matplotlib.patches.Circle(xy=(x,y), radius=p,
fill=True,linestyle="dashed",facecolor='g',edgecolor="g")
ax.add_artist(patch_cercles)
# Tracé d'un arc
theta_arc=[min(theta_degs),max(theta_degs)]
patch_arc100 = matplotlib.patches.Arc(xy=(0,0), width=r_arc*2, height=r_arc*2,
theta1=theta_arc[0], theta2=theta_arc[1],fill=False,linestyle="dashed",
facecolor='w',edgecolor="r")
ax.add_artist(patch_arc100)
ax.grid()
ax.set_xlim(-120,140)
ax.set_ylim(-120,120)
ax.set_title('Titre')
plt.show() |
Partager