0
import matplotlib.pyplot as plt

fig = plt.figure("Histogram")
ax = fig.add_subplot(1,1,1)
ax.hist([10,10,10,10,10,21,12,23,35,45,60,33,22,56,34,28,40,41],bins=7,ec='black',color = 'b')

plt.title("Distribution")
plt.xlabel("Range")
plt.ylabel("Amount")
plt.show()

this is the simple program to make a histogram My question is if I remove plt from

plt.title("Distribution")
plt.xlabel("Range")
plt.ylabel("Amount")
plt.show()

And rewrite my code like this

ax.set_title("Distribution")
ax.set_xlabel("Range")
ax.set_ylabel("Amount")
plt.show()
  1. Why are both of the versions same?

  2. What are the difference between functions xlabel and set_xlabel/ylabel and set_ylabel

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
darkweb
  • 3
  • 2
  • You are manipulating two different classes : [`pyplot`](https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xlabel) and an [`axes`](https://matplotlib.org/api/axes_api.html). Take a look at this question : https://stackoverflow.com/questions/43482191/matplotlib-axes-plot-vs-pyplot-plot – Hugo Mar 20 '18 at 08:45
  • @ Hugo pyplot is a class? I thought it was a file – darkweb Mar 20 '18 at 09:49
  • 1
    sorry for my lack of research. all the comments are usefull – darkweb Mar 20 '18 at 09:57

0 Answers0