From 28094bf4cec24100e79d9f285d3b6bbb0b0a3be9 Mon Sep 17 00:00:00 2001 From: Chanumask <joelfriedrich@gmx.de> Date: Fri, 10 May 2024 10:25:35 +0200 Subject: [PATCH] centered the arrows and text for better readability in plt action maps and added colored arrow assets --- .../plotting/action_assets/green_arrow.png | Bin 0 -> 455 bytes .../plotting/action_assets/grey_arrow.png | Bin 0 -> 425 bytes .../plotting/action_assets/red_arrow.png | Bin 0 -> 439 bytes .../plotting/action_assets/yellow_arrow.png | Bin 0 -> 443 bytes .../utils/plotting/plot_single_runs.py | 2 +- marl_factory_grid/utils/renderer.py | 31 ++++++++---------- 6 files changed, 14 insertions(+), 19 deletions(-) create mode 100644 marl_factory_grid/utils/plotting/action_assets/green_arrow.png create mode 100644 marl_factory_grid/utils/plotting/action_assets/grey_arrow.png create mode 100644 marl_factory_grid/utils/plotting/action_assets/red_arrow.png create mode 100644 marl_factory_grid/utils/plotting/action_assets/yellow_arrow.png diff --git a/marl_factory_grid/utils/plotting/action_assets/green_arrow.png b/marl_factory_grid/utils/plotting/action_assets/green_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..9e248a81b10c76e39441574f1da88a8d51421be4 GIT binary patch literal 455 zcmV;&0XY7NP)<h;3K|Lk000e1NJLTq002Ay002A)1^@s6I{evk00009a7bBm000XU z000XU0RWnu7ytkPc}YY;RCt{2nz2d)K@>%YV9-`OyC8mmkXE@b2$EXZeG&`1KpHDc zA&sBn9|*Q@C1RDYu-8(Mh>?wojl`@;cK2=WfoT^GGpCq+69OS*ZpQsubJ(qiRiKsV zu~_^prZ1A5oQEodL?cObB#Dl{7c9OEt0F5^mBtj=%1L7e*~&;GgRFaL{6p5QH0F?X zCyfQjx{<~LWlJxOCCHXm8cUQdoiuWgEsZpClr3DkmEL-Cmi>{|i+pXz{TfW4ijbWM zC;E19ce<UMFAQs+_t|2EzjnEin{WzDdj(04VDVKbg66PW-yd`~r>)7~jSNDEgU-&h z@4?PCLYYCv){h>dt>76@Sh>T(BkdTlVP(U@h8+VotZZ1=uw%f6l?@9Ub`03CvSDGv zjsY81HY{w|F<`^WhJ_6~Ml61ud6;JU-o9<G2hYItI>TiDK6nQf?aneIhUqIT+6z?x xrVUBroAhnQZ^t;@*~-ZN^<uz%vxI~~`2Y%JM&KQ4%B}za002ovPDHLkV1hE9#r6OI literal 0 HcmV?d00001 diff --git a/marl_factory_grid/utils/plotting/action_assets/grey_arrow.png b/marl_factory_grid/utils/plotting/action_assets/grey_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..fcfffb9ed07009c794994c4ce74203fc8d1b0deb GIT binary patch literal 425 zcmV;a0apHrP)<h;3K|Lk000e1NJLTq002Ay002A)1^@s6I{evk00009a7bBm000XU z000XU0RWnu7ytkPTS-JgRCt{2nlVbmKoo`_;-al~c8hob&$8elY^*GWG+rR^|8E#l zY~u~Qf+w-pQjisufP#g@#NAEuvi}FK4SdXe#bm}z2(d0jQS9ZMXSNHFTmX0``2yg| zri{B^kX(`c_#OZ^wkxuns<b!APEOie$WBJuJIIEY_J7ERmG(7c!%6!FWWz}N24zPt z?OTu?t+a1Zc68F-gY0Oey+_%>rAaROmi;l;y`N_RJPjmUuku^Y`J_+b{rWsRlyE&M zrMdM9fXjiTR{(Bp2y)IdcRy;HufH3uh1~tL>3hrN^3cW%I<{U_)v-ke5~fy|+R}l6 z8m1bi8V(H9Fx4>CaA2T@sfMYB0|PZoHB2=e7^q>YVXEQ4Kn+t3Qw;|Oz+;Dt?)S1R z4=gey?>gKbK3H@BoVB?l2Ji~t+@?TEX-@LKew*>zHm+B8GO~ZY7zp325H={ExDc5y TAiRU`00000NkvXXu0mjfg)q90 literal 0 HcmV?d00001 diff --git a/marl_factory_grid/utils/plotting/action_assets/red_arrow.png b/marl_factory_grid/utils/plotting/action_assets/red_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..1a23abb331eebadb55c4a168684362a758d072e6 GIT binary patch literal 439 zcmV;o0Z9IdP)<h;3K|Lk000e1NJLTq002Ay002A)1^@s6I{evk00009a7bBm000XU z000XU0RWnu7ytkPX-PyuRCt{2nlVnpKoCV&hzMHf=pw`cxIx-TDV+I|>vWcAs3?)r za1?I96><`KC`tZ;SY*;rAQO|s_Bj7Z(^`7keZ_h=1R=z>r1|_P6~!PN0;}m11YT+O z7R_!$pP^Y!;5`EA$J~bll1;soX0>d;q`8@FKcrbt*0(hOC+kz1+sXQp=5AztNOQNc z-InHlWV<QN{mOPrn$5^|Lz>OXwky3_pL&{>U60va<L6nLy|f|=B$|CBvy0}0N2BBK z^K47P<t(#o7@8ykH*H9l8PV(^v_UG0L7Gg?s;2zAQETOZ%gS%gW~ZUcux9Hi&(DKr zC}C)YqqekTsD`12qZ)P$)iBg>RKt#;8ipE<YS=MU!%)Lf4LgQv7-~4GVaHGnLk&kY z?3f5V*SHG(OyluM@Js|AYuxNFf_IjAeznORG0n&<yAFL|nPo!)PvzT;-?nkNvb~Z0 h^TmMoW`zi?@&y5qEsun^QsMvr002ovPDHLkV1ktJ$ZG%q literal 0 HcmV?d00001 diff --git a/marl_factory_grid/utils/plotting/action_assets/yellow_arrow.png b/marl_factory_grid/utils/plotting/action_assets/yellow_arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..786cbbd8feec89dc6b9259399657526e8b2c7b8f GIT binary patch literal 443 zcmeAS@N?(olHy`uVBq!ia0vp^HXzKw1|+Ti+$;i8oCO|{#S9GG!XV7ZFl&wk0|R5O zr;B4q#hkaZHhM8T3be5sW~}bGIdOsGCkDIj2hKMlBBOq3>}yPrPPxA1Wbln_%@#?S zog%kRR2rUqd-mD?gxk&ich}Fjt;)o(rc3hejh?D4ydFH$Cmq^-<ikS!8fVqThB2N= z7ms|~o3vx`+KIlcUfFYVGB4e7*(Q=1>vnDTmVfToR&QCS^x8M-y5eissOy@yOEd4b z<b*FRoxCY_@-?%R-AZe7Pd%G9?dX-uo8I()$$kBK&5;k&T+KFmCT)GLoabNRv%9;} zY;wWYoLllivopA^TP|7Mqw>l2>4CH>n=7gUwy)YR?fo{!#%}%JXFqc0@9NRHxyzTW z{fT6wL2|pO`z^z!Hc4J>sj{90iEf9x+GLe8W?bB`DDgOlRGP_}j2jrzntROlarOSm z^j~cIsprUt3xB>DsC?@4Wm~LPenjYS%{)K76)ZrfWIa0mD)(6a@g28rCZ+tZF?_H$ dl0ic|{$a^mt*0t`4gq6>!PC{xWt~$(697@0%S`|P literal 0 HcmV?d00001 diff --git a/marl_factory_grid/utils/plotting/plot_single_runs.py b/marl_factory_grid/utils/plotting/plot_single_runs.py index 6394de4..ffeb849 100644 --- a/marl_factory_grid/utils/plotting/plot_single_runs.py +++ b/marl_factory_grid/utils/plotting/plot_single_runs.py @@ -121,7 +121,7 @@ def plot_routes(factory, agents): def plot_action_maps(factory, agents): - renderer = Renderer(factory.map.level_shape, custom_assets_path={ + renderer = Renderer(factory.map.level_shape, cell_size=80, custom_assets_path={ 'green_arrow': 'marl_factory_grid/utils/plotting/action_assets/green_arrow.png', 'yellow_arrow': 'marl_factory_grid/utils/plotting/action_assets/yellow_arrow.png', 'red_arrow': 'marl_factory_grid/utils/plotting/action_assets/red_arrow.png', diff --git a/marl_factory_grid/utils/renderer.py b/marl_factory_grid/utils/renderer.py index 9681e4e..288e2c0 100644 --- a/marl_factory_grid/utils/renderer.py +++ b/marl_factory_grid/utils/renderer.py @@ -278,7 +278,7 @@ class Renderer: walls which cover the entire grid cell. """ self.fill_bg() - font = pygame.font.Font(None, 18) + font = pygame.font.Font(None, 20) # prepare position dict to iterate over position_dict = defaultdict(list) @@ -286,18 +286,7 @@ class Renderer: position_dict[tuple(entity.pos)].append(entity) for position, entities in position_dict.items(): - num_entities = len(entities) entity_size = self.cell_size // 2 # Adjust size to fit multiple entities for non-wall entities - - # Define offsets for each direction based on a quadrant layout within the cell - offsets = { - 0: (-entity_size // 2, -entity_size // 2), # North - 90: (-entity_size // 2, entity_size // 2), # East - 180: (entity_size // 2, entity_size // 2), # South - 270: (entity_size // 2, -entity_size // 2) # West - } - - # Sort entities based on direction to ensure consistent positioning entities.sort(key=lambda x: x.rotation) for entity in entities: @@ -306,31 +295,37 @@ class Renderer: print(f"Error: No asset available for '{entity.name}'. Skipping rendering this entity.") continue - img = pygame.transform.rotate(img, entity.rotation) - # Check if the entity is a wall and adjust the size and position accordingly if entity.name == 'wall': img = pygame.transform.scale(img, (self.cell_size, self.cell_size)) img_rect = img.get_rect(center=(position[0] * self.cell_size + self.cell_size // 2, position[1] * self.cell_size + self.cell_size // 2)) else: - img = pygame.transform.scale(img, (entity_size, entity_size)) # Scale down the image for arrows + # Define offsets for each direction based on a quadrant layout within the cell + offsets = { + 0: (0, -entity_size // 2), # North + 90: (-entity_size // 2, 0), # West + 180: (0, entity_size // 2), # South + 270: (entity_size // 2, 0) # East + } + img = pygame.transform.scale(img, (int(entity_size), entity_size)) offset = offsets.get(entity.rotation, (0, 0)) img_rect = img.get_rect(center=( position[0] * self.cell_size + self.cell_size // 2 + offset[0], position[1] * self.cell_size + self.cell_size // 2 + offset[1] )) + img = pygame.transform.rotate(img, entity.rotation) self.screen.blit(img, img_rect) # Render the probability next to the icon if it exists and is non-zero if entity.probability > 0 and entity.name != 'wall': - formatted_probability = f"{entity.probability:.4f}" - prob_text = font.render(formatted_probability, True, (0, 0, 0)) # Black color for readability + formatted_probability = f"{entity.probability * 100:.2f}" + prob_text = font.render(formatted_probability, True, (0, 0, 0)) prob_text_rect = prob_text.get_rect(center=img_rect.center) # Center text on the arrow self.screen.blit(prob_text, prob_text_rect) - pygame.display.flip() # Update the display + pygame.display.flip() self.save_screen("multi_action_graph") def save_screen(self, filename):