improve formatting
This commit is contained in:
parent
78dc4b8763
commit
c64d06b205
1 changed files with 17 additions and 9 deletions
26
src/main.py
26
src/main.py
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/env -S python
|
#!/bin/env -S python
|
||||||
|
|
||||||
from matplotlib import pyplot
|
from matplotlib import pyplot, patheffects
|
||||||
from matplotlib.axes import Axes
|
from matplotlib.axes import Axes
|
||||||
from adjustText import adjust_text
|
from adjustText import adjust_text
|
||||||
|
|
||||||
|
@ -8,20 +8,19 @@ from adjustText import adjust_text
|
||||||
from data import (pay, release)
|
from data import (pay, release)
|
||||||
|
|
||||||
|
|
||||||
def center(data: list[tuple[str, list[float]]], padding: float = 0):
|
def center(data: list[tuple[str, list[float]]]):
|
||||||
for axis_index in range(len(data[0][1])):
|
for axis_index in range(len(data[0][1])):
|
||||||
min_ = min(data, key=lambda e: e[1][axis_index])[1][axis_index]
|
min_ = min(data, key=lambda e: e[1][axis_index])[1][axis_index]
|
||||||
max_ = max(data, key=lambda e: e[1][axis_index])[1][axis_index]
|
max_ = max(data, key=lambda e: e[1][axis_index])[1][axis_index]
|
||||||
delta = max_ - min_
|
delta = max_ - min_
|
||||||
desired_bias = (1 - padding)
|
|
||||||
desired_delta = 2 * desired_bias
|
|
||||||
for (_, values) in data:
|
for (_, values) in data:
|
||||||
original = values[axis_index]
|
original = values[axis_index]
|
||||||
value = (original - min_) / delta
|
value = (original - min_) / delta
|
||||||
value = (value * desired_delta) - desired_bias
|
value = (value * 2) - 1
|
||||||
values[axis_index] = value
|
values[axis_index] = value
|
||||||
|
|
||||||
|
|
||||||
|
# from some image, online
|
||||||
to_rank = {
|
to_rank = {
|
||||||
'c#',
|
'c#',
|
||||||
'assembly',
|
'assembly',
|
||||||
|
@ -76,7 +75,7 @@ ranked = list[tuple[str, list[float]]](
|
||||||
for label in to_rank
|
for label in to_rank
|
||||||
if label in pay and label in release
|
if label in pay and label in release
|
||||||
)
|
)
|
||||||
center(ranked, 0.1)
|
center(ranked)
|
||||||
|
|
||||||
|
|
||||||
print("\nunused", [l for l in pay.keys() if not l in map(lambda e: e[0], ranked)])
|
print("\nunused", [l for l in pay.keys() if not l in map(lambda e: e[0], ranked)])
|
||||||
|
@ -87,10 +86,19 @@ print("\nranked", ranked)
|
||||||
|
|
||||||
(figure, axes) = pyplot.subplots()
|
(figure, axes) = pyplot.subplots()
|
||||||
assert type(axes) is Axes
|
assert type(axes) is Axes
|
||||||
axes.plot([-1, 1], [0, 0])
|
axes.axhline(y=0, color='k')
|
||||||
axes.plot([0, 0], [-1, 1])
|
axes.axvline(x=0, color='k')
|
||||||
texts = [axes.text(p, r, l) for (l, [r, p]) in ranked]
|
axes.set_xlim(-1, 1)
|
||||||
|
axes.set_ylim(-1, 1)
|
||||||
|
axes.axis("off")
|
||||||
|
drop_white = patheffects.withStroke(linewidth=3,foreground="white")
|
||||||
|
texts = [axes.text(p, r, l, path_effects=[drop_white]) for (l, [r, p]) in ranked]
|
||||||
adjust_text(texts, only_move={'points':'y', 'texts':'y'})
|
adjust_text(texts, only_move={'points':'y', 'texts':'y'})
|
||||||
|
|
||||||
|
|
||||||
|
axes.text(1.1, 0, 'connait\nle sexe', path_effects=[drop_white])
|
||||||
|
axes.text(-1.3, 0, 'ne connait\npas le sexe', path_effects=[drop_white])
|
||||||
|
axes.text(0, 1.1, 'a le\nsexe', path_effects=[drop_white])
|
||||||
|
axes.text(0, -1.2, 'n\'a pas\nle sexe', path_effects=[drop_white])
|
||||||
|
|
||||||
pyplot.show()
|
pyplot.show()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue