Bonjour,

Je code actuellement un schéma qui va varier en fonction de différents inputs de l'utilisateur. Ce schéma doit être aligné avec un tableau (en background) afin de donner du contexte.

J'ai donc décidé d'utiliser la librairie Matplotlib afin de dessiner des flèches arrondies, puis des flèches et des points.
Je n'ai peut-être pas pris la librairie la plus appropriée. Si vous en voyez une autre, je suis preneur.

Mon problème, est que le tableau peut dépasser la largeur de la fenêtre affichée, quand l'input (le seul actuellement renseigné dans le code) est supérieur à 4. Est-ce qu'il y a un moyen d'avoir le tableau toujours correctement affiché ?
J'ai cru trouver une piste en changeant les dimensions dans subplots (ligne 50), mais ça ne fonctionne pas, ou ça déforme les formes dessinées (cercle).

Voici le code que j'ai actuellement :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
import numpy as np
import matplotlib.patches as mpatches 
from matplotlib.collections import PatchCollection
import matplotlib.pyplot as plt
 
def DrawCoil(Center, Radius, Variante, Direction):
    if Variante == 'A':
        RingColor = '#FF0000'
    elif Variante == 'B':
        RingColor = '#0070C0'
    elif Variante == 'C':
        RingColor = '#00B050'
    else:
        RingColor = '#000000'
 
    if Direction == 'CCW':
        RingStart=140
        RingEnd=90
    else:
        RingStart=-270
        RingEnd=40
 
    # Create the ring
    rwidth = Radius/5
    Ring = mpatches.Wedge(Center, Radius, RingStart, RingEnd, width=rwidth)
 
    # Create the arrow
    offset = 0.02
    ycenter = Center[1] + Radius - (rwidth/2)
    top = [Center[0], ycenter + offset]
    bottom = [Center[0], ycenter - offset]
    if RingStart > 0:
        left = [Center[0] - 0.05, ycenter]
    else:
        left = [Center[0] + 0.05, ycenter]
    arrow  = plt.Polygon([top, bottom, left, top])
 
    p = PatchCollection(
        [Ring, arrow], 
        edgecolor = None, 
        facecolor = RingColor
    )
    ax.add_collection(p)
 
 
NbRoutage = int(input("Nombre de routage : "))
ColCorrection = 0.27 * NbRoutage - 1.25
ColCorrection = 0
 
fig, ax = plt.subplots(figsize = (6, 6))
 
 
x = .35
DrawCoil((x, .165), .06, 'A', 'CW')
x = x + 0.17
DrawCoil((x, .165), .06, 'B', 'CW')
x = x + 0.17
DrawCoil((x, .165), .06, 'C', 'CW')
x = x + 0.17
DrawCoil((x, .165), .06, 'A', 'CCW')
x = x + 0.17
DrawCoil((x, .165), .06, 'B', 'CCW')
x = x + 0.17
DrawCoil((x, .165), .06, 'C', 'CCW')
 
Row1 = ['Départ 1']
Row2 = ['Départ 2']
Row3 = ['Départ 3']
Row4 = ['Départ 4']
Row5 = ['']
Row6 = ['Rootage']
Row7 = ['Numérotation']
ColWidths = [.25]
 
for i in range(NbRoutage):
    Row1.append('')
    Row2.append('')
    Row3.append('')
    Row4.append('')
    Row5.append('')
    Row6.append('')
    Row7.append(i + 1)
    ColWidths.append(.17)
 
data = np.vstack([Row1, Row2, Row3, Row4, Row5, Row6, Row7])
 
 
 
TheTable = plt.table(cellText=data, cellLoc='center', colWidths=ColWidths, loc='lower left')
cellDict = TheTable.get_celld()
for i in range(0, NbRoutage + 1):
    for j in range(0, len(data)):
        cellDict[(j,i)].set_height(.075)
    cellDict[(len(data) - 3, i)].set_height(.2)
    cellDict[(len(data) - 2, i)].set_height(.15)
 
plt.subplots_adjust(left=0, bottom=0)
 
plt.axis('off')
plt.show()