How to show matplotlib images in Visual Studio 2019 with Python

Gilad Pellaeon 1 Reputation point
2021-09-29T07:04:34.95+00:00

Atm I learn Python to do ML. I use Visual Studio 2019 as IDE (not Visual Studio code!). To show image data I installed and imported matplotlib. Here is an excerpt how I call matplotlib

. . .

for image_batch, label_batch in dataset.take(1):
    print(image_batch.shape)
    print(label_batch.numpy())
    plt.imshow(image_batch[0].numpy().astype("uint8"))
    plt.title(class_names[label_batch[0]])
    plt.axis("off")

My example code runs without an error. But the program only prints text in the console. There is no windows showing my picture. I tried to find a solution how to use matploblib in Visual Studio, but I only found information about how to achieve it in Visual Studio Code. What must I do or which extension must install to see the plotted images?

Best regards

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,604 questions
{count} votes

1 answer

Sort by: Most helpful
  1. PengGe-MSFT 3,331 Reputation points
    2021-09-29T09:22:59.427+00:00

    Hi, @Gilad Pellaeon

    Welcome to Microsoft Q&A!

    You can try to add the following content to your code:

    plt.show()  
    

    Then try to run again.

    Sincerely,
    Peng
    *
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread

    0 comments No comments