Repository: AUTOMATIC1111/stable-diffusion-webui

Issue:
[Bug]: X/Y/Z Plot is adding an extra image between the generated ones
### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits

### What happened?

Hello.

it does not matter the size of the plot it always add an image between the generated ones. making the grid unnecessary bigger.

Even with a large margin it adds an image

![image](https://user-images.githubusercontent.com/116231978/217324678-20e1d917-f870-487f-892b-be8fe49c4f1d.png)

![xyz_grid-0000-1655128259](https://user-images.githubusercontent.com/116231978/217325456-6ca85995-e44a-44ea-98df-4fa5e25762ac.jpg)

![image](https://user-images.githubusercontent.com/116231978/217327594-d0a18e73-9b71-4586-b06a-245043768397.png)





### Steps to reproduce the problem

Prompt:
sharp focus of a plant growing from the dirt, blutrry nature green background, highly defined, photorealism, reality picture,depth of field

Steps: 60,
Sampler: Euler a,
CFG scale: 7.5,
Seed: 1655128259,
Size: 512x768,
Model hash: b5fcd73ddc,
Model: dreambox-mix-A,
Script: X/Y/Z plot,
X Type: Checkpoint name,
X Values: "dreambox-mix-A.ckpt, SlimeX.safetensors,",
Y Type: Sampler, Y Values: "Euler a, LMS"

![image](https://user-images.githubusercontent.com/116231978/217327976-410b8a2a-08f2-4419-abf6-16fbc539fd59.png)


### What should have happened?

display the grid without extra images

### Commit where the problem happens

ea9bd9f

### What platforms do you use to access the UI ?

Windows

### What browsers do you use to access the UI ?

Google Chrome

### Command Line Arguments

```Shell
set COMMANDLINE_ARGS=--listen --no-half --precision full --port 9999 --disable-safe-unpickle --deepdanbooru --reinstall-torch --reinstall-xformers --enable-insecure-extension-access
```


### List of extensions

deforum
stable-diffusion-webui-instruct-pix2pix | https://github.com/Klace/stable-diffusion-webui-instruct-pix2pix.git
LDSR | built-in |  
Lora | built-in |  
ScuNET | built-in |  
SwinIR | built-in |  
prompt-bracket-checker | built-in



### Console logs

```Shell
X/Y/Z plot will create 8 images on 1 4x2 grid. (Total steps to process: 480)
                                  Loading weights [b5fcd73ddc] from F:\auto1111\models\Stable-diffusion\dreambox-mix-A.ckptal progress: 0it [00:00, ?it/s]
Applying cross attention optimization (Doggettx).
Weights loaded in 7.5s (load weights from disk: 5.9s, apply weights to model: 0.5s, move model to device: 1.1s).
100%|██████████████████████████████████████████████████████████████████████████████████| 60/60 [00:31<00:00,  1.91it/s]
100%|██████████████████████████████████████████████████████████████████████████████████| 60/60 [00:31<00:00,  1.91it/s]
Loading weights [d1004a4e24] from F:\auto1111\models\Stable-diffusion\mjstyle.ckpt   | 120/480 [01:12<03:08,  1.91it/s]
Applying cross attention optimization (Doggettx).
Weights loaded in 3.1s (load weights from disk: 1.6s, apply weights to model: 0.4s, move model to device: 1.1s).
100%|██████████████████████████████████████████████████████████████████████████████████| 60/60 [00:31<00:00,  1.90it/s]
100%|██████████████████████████████████████████████████████████████████████████████████| 60/60 [00:31<00:00,  1.91it/s]
Loading weights [f22782eb52] from F:\auto1111\models\Stable-diffusion\SlimeX.safetensors40/480 [02:21<02:05,  1.91it/s]
Applying cross attention optimization (Doggettx).
Weights loaded in 2.9s (load weights from disk: 0.2s, apply weights to model: 1.8s, move model to device: 0.9s).
100%|██████████████████████████████████████████████████████████████████████████████████| 60/60 [00:31<00:00,  1.89it/s]
100%|██████████████████████████████████████████████████████████████████████████████████| 60/60 [00:31<00:00,  1.91it/s]
Loading weights [d1004a4e24] from F:\auto1111\models\Stable-diffusion\mjstyle.ckpt   | 360/480 [03:29<01:02,  1.91it/s]
Applying cross attention optimization (Doggettx).
Weights loaded in 2.1s (load weights from disk: 0.8s, apply weights to model: 0.4s, move model to device: 0.9s).
100%|██████████████████████████████████████████████████████████████████████████████████| 60/60 [00:31<00:00,  1.91it/s]
100%|██████████████████████████████████████████████████████████████████████████████████| 60/60 [00:31<00:00,  1.91it/s]
Total progress: 100%|████████████████████████████████████████████████████████████████| 480/480 [04:38<00:00,  1.72it/s]
{"prompt": "sharp focus of a plant growing from the dirt, blutrry nature green background, highly defined, photorealism, reality picture,depth of field", "all_prompts": ["sharp focus of a plant growing from the dirt, blutrry nature green background, highly defined, photorealism, reality picture,depth of field"], "negative_prompt": "", "all_negative_prompts": [""], "seed": 1655128259, "all_seeds": [1655128259], "subseed": 1013077508, "all_subseeds": [1013077508], "subseed_strength": 0, "width": 512, "height": 768, "sampler_name": "Euler a", "cfg_scale": 7.5, "steps": 60, "batch_size": 1, "restore_faces": false, "face_restoration_model": null, "sd_model_hash": "b5fcd73ddc", "seed_resize_from_w": 0, "seed_resize_from_h": 0, "denoising_strength": null, "extra_generation_params": {}, "index_of_first_image": 0, "infotexts": ["sharp focus of a plant growing from the dirt, blutrry nature green background, highly defined, photorealism, reality picture,depth of field\nSteps: 60, Sampler: Euler a, CFG scale: 7.5, Seed: 1655128259, Size: 512x768, Model hash: b5fcd73ddc, Model: dreambox-mix-A"], "styles": [], "job_timestamp": "20230207125234", "clip_skip": 1, "is_using_inpainting_conditioning": false}
```


### Additional information

_No response_


Discussion:
I faced the same when there was an extra comma or CR/LF (ex. Pressing <kbd>Enter</kbd> after checkpoint/sampler name) between names or after the last name. Seems to be the case here.
Yes the issue is that you have a bunch of newlines after your checkpoint names and those are getting accidentally interpreted. Do not use newlines, just comma space and then the next entry.
This should not be close, it should be fixed. is not like is something out of the ordinary use ENTER instead of space.
But I guess if anyone else have this issue they will know how to work around

Resolving patch:
diff --git a/scripts/xyz_grid.py b/scripts/xyz_grid.py
--- a/scripts/xyz_grid.py
+++ b/scripts/xyz_grid.py
@@ -418,7 +418,7 @@ def process_axis(opt, vals):
             if opt.label == 'Nothing':
                 return [0]
 
-            valslist = [x.strip() for x in chain.from_iterable(csv.reader(StringIO(vals)))]
+            valslist = [x.strip() for x in chain.from_iterable(csv.reader(StringIO(vals))) if x]
 
             if opt.type == int:
                 valslist_ext = []


Test patch: