The graph defined by the function in Colaboratory is not displayed

Asked 1 years ago, Updated 1 years ago, 275 views

I was running it on the Jupiter Notebook, but when I ran it on the Collaboration, the graph disappeared.

Please let me know if you know where to fix it.Thank you for your cooperation.

import matplotlib

defjp_us():
    year=[1950, 1980, 2000, 2015, 2016]
    japan = [82, 116, 126, 127, 126]
    usa=[158,230,283,322,324]
    matplotlib.pyplot.plot(year, japan, color='#FF0000', label='japan')
    matplotlib.pyplot.plot(year, usa, color='#00FF00', label='usa')
    matplotlib.pyplot.legend()
    
    matplotlib.pyplot.show()

python python3 google-colaboratory

2022-09-30 21:49

2 Answers

If this is all about the program, then the function is defined but not called, and therefore the contents of the function are not running.Please call the function.


2022-09-30 21:49

After the def block, indentation is removed and a call to the jp_us function is added.

Calling the jp_us#jp_us function 
matplotlib.pyplot.plot(year, japan, color='#FF0000', label='japan')
matplotlib.pyplot.plot(year, usa, color='#00FF00', label='usa')
matplotlib.pyplot.legend()
    
matplotlib.pyplot.show()


2022-09-30 21:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.