1

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.

4
  • Hey, could you paste the code to help people understand. Thanks Commented Sep 12, 2019 at 18:20
  • Is this what you're looking for? Commented Sep 12, 2019 at 18:27
  • Hey I've had a guess at what you are trying to do based on the code. If it answers your question can you accept please. Thanks Commented Sep 12, 2019 at 18:33
  • Thank you all, I got it to work by highlighting all the steps together then pressing shift and enter. Commented Sep 12, 2019 at 18:53

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

You can first create an matplotlib.axes.Axes and then plot on it:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.scatter(L, T)
ax.set_xlabel('Local Time')
ax.set_ylabel('Surface Temperature')
ax.set_title('Surface Temperature vs. Local Time')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.