#๐Ÿ”’ Matplotlib display error

4 messages ยท Page 1 of 1 (latest)

opal sigilBOT
#

@harsh plinth

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

harsh plinth
#
def img_show(img, ax=None, figsize=(16,8)):
    if ax is None: fig, ax = plt.subplots(figsize=figsize)
    ax.xaxis.tick_top()
    ax.imshow(img)
    return ax
        
def draw_box(img, ax, bb, lbl):
    if lbl == 'With Helmet':
        color_lbl = 'red'
    
    else:
        color_lbl = 'blue'
    
    rect = patches.Rectangle(
        (int(bb[0]),int(bb[1])), int(bb[2])-int(bb[0]), int(bb[3])-int(bb[1]),
        fill=False, edgecolor=color_lbl, lw=2
    )
    ax.add_patch(rect)
def plot_sample(a_img, tgt, ax=None, figsize=(16,8)):
    img = np.array(a_img).copy()
    img = img*255
    img = np.transpose(img, (2,1,0))
    tr_img = scipy.ndimage.rotate(img, 270, reshape=False)
    tr_img = np.flip(tr_img, axis=1)
    ax = img_show(tr_img, ax=ax)
    
    for box_id in range(len(tgt['boxes'])):
        box = tgt['boxes'][box_id]
        lbl = CLASS_NAME[tgt['labels'][box_id]]
        draw_box(tr_img, ax, box, lbl)

for i in range(3):
    a_img, trgt = train_dataset[i]
    plot_sample(a_img, trgt)
opal sigilBOT
#

@harsh plinth

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.