I found that when the text contains a lot of spaces, the output of print()
will be different from the output of plt.annotate()
My question is : How can I make the output of annotate() the same as print() in matplotlib?
I use the following code to compare the output of print()
with the output of plt.annotate()
:
from matplotlib import pyplot as plt
import json
with open("epoch_3350-20230218172431.json", "r") as source:
log_dict = json.load(source)
print(log_dict["model_structure"])
plt.figure(figsize=(25, 10))
plt.annotate(text=f"{log_dict.get('model_structure').__str__()}",
xy=(0.08, 0.5), bbox={'facecolor': 'green', 'alpha': 0.4, 'pad': 5},
fontsize=14, xycoords='axes fraction', va='center')
plt.show()
plt.close()
output of print()
:
MTSCorrAD(
(gin_convs): ModuleList(
(0): GINConv(nn=Sequential(
(0): Linear(in_features=1, out_features=3, bias=True)
(1): BatchNorm1d(3, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(2): ReLU()
(3): Linear(in_features=3, out_features=3, bias=True)
(4): ReLU()
))
)
(gru1): GRU(3, 8)
(lin1): Linear(in_features=8, out_features=3, bias=True)
)
====================================================================================================
+-------------------------+-----------------------------+-----------------+----------+
| Layer | Input Shape | Output Shape | #Param |
|-------------------------+-----------------------------+-----------------+----------|
| MTSCorrAD | [792, 1], [2, 52272], [792] | [3] | 363 |
| ├─(gin_convs)ModuleList | -- | -- | 24 |
| │ └─(0)GINConv | [792, 1], [2, 52272] | [792, 3] | 24 |
| ├─(gru1)GRU | [12, 3] | [12, 8], [1, 8] | 312 |
| ├─(lin1)Linear | [8] | [3] | 27 |
+-------------------------+-----------------------------+-----------------+----------+
As the results show, the output of print()
is different from the output of plt.annotate()
.
PS.
- I put the file in google drive: https://drive.google.com/drive/folders/1_KMwCzf1diwS4gGNdSSxG7bnemqQkFxI?usp=sharing