Issue
I am trying to plot a graph on python using the function matplotlib.pyplot and it seems that when I run the codes, they apply but to separate graphs. So when I applied plt.scatter(Lt, T) it showed the graph, then when I applied plt.xlabel('Local Time (hours)') it did run but to a new graph without the data inputed when I ran put.scatter(Lt,T) so basically I get a plain graph with only an x-axis title.
import matplotlib.pyplot as plt
plt.scatter(L, T)
plt.axis([0,25,200,800])
plt.xlabel('Local Time')
plt.ylabel('Surface Temperature')
plt.title('Surface Temperature vs. Local Time')
I expect all the codes and functions to apply to the same graph.
Solution
I think you need use the show method. You usually add this at the end after you've defined the axes etc. Sometimes it makes sense to wrap it in a function like below.
import matplotlib.pyplot as plt
def plotter(L,T):
plt.scatter(L, T)
plt.axis([0,25,200,800])
plt.xlabel('Local Time')
plt.ylabel('Surface Temperature')
plt.title('Surface Temperature vs. Local Time')
plt.show()
plotter(L,T)
Hope that helps.
Answered By - bamdan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.