How can I fix this matplotlib issue?

Question:

import matplotlib.pyplot as plt
import numpy as np

x = np.array(["A", "B", "C", "D"])
y = np.array([3, 8, 1, 10])

plt.bar(x,y)
plt.show()

It doesn’t show me the diagram! Only this text:

<BarContainer object of 4 artists>

This code is simple, so as to be more comprehensive. I was trying to visualize some data and jupyter did not show me the diagram. Then, I tried to run this simple code and it showed me this text, instead of a diagram. Can you help me please?

Asked By: GRG 27

||

Answers:

It’s a bit strange because your code should work too. Maybe try this, see if the output is the same:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_axes([0,0,1,1])

x = np.array(["A", "B", "C", "D"])
y = np.array([3, 8, 1, 10])

ax.bar(x,y)
plt.show()

I leave you a link to lots of useful tutorials.

Answered By: ClaudiaR