Home > Blockchain >  matplotlib presentation with regards to plt.show() vs semi-colon
matplotlib presentation with regards to plt.show() vs semi-colon

Time:01-04

Not so much a problem but rather what is the 'industry standard' with regards to plt.plot(); and plt.show() following plt.plot()?

In my experience so far, it seems plt.plot() then plt.show() seems more common, but I'm looking to draw on more experienced programmers.

CodePudding user response:

A semi-colon in Python denotes separation, rather than termination. It allows you to write multiple statements on the same line. For example instead of writing:

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

You can use a semi colon to write these 3 lines of code on a single line:

plt.plot(x, y); plt.show()

In my opinion, I think that the code is more readable/understandable when writing the code on seperate lines, however some people may think different. It is not always good to write on seperate lines because when using list comprehensions, you can write in 10 lines or 1 line, which means they take up less space and computer memory.

  • Related