1

I am trying to plot two graphs separately, but i couldn't. For this problem i have two lists, which are like:

year=[1950, 1951, 1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959]

pop=[2.53, 2.57, 2.62, 2.67, 2.71, 2.76, 2.81, 2.86, 2.92, 2.97]

Then i made a code which is:

import matplotlib.pyplot as plt

# Make a line plot: year on the x-axis, pop on the y-axis
a=plt.plot(year,pop)

# Make a scatter plot: year on the x-axis, pop on the y-axis
b=plt.scatter(year,pop)

#show them
plt.show()

Of course i know that this plot both in same graph, i read this post but i couldn't fix my code. I am just a beginner so i came here for some help. Would you help me?

EDIT

I do not know really how to implement what is in the other answer, because i've never used plt.figure yet.. I think something like add_subplot should be used but don't know how.

  • What changes did you tried after reading that post you mention? Do add them to your question so we can help better. Also, take the time to go through the [welcome tour](https://stackoverflow.com/tour) to know your way around here (and also to earn your first badge) ;) – DarkCygnus Jun 26 '17 at 23:54
  • @GrayCygnus i will do it. thank you –  Jun 27 '17 at 00:03

1 Answers1

0

Try this:

import matplotlib.pyplot as plt
year = [1950, 1951, 1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959]
pop = [2.53, 2.57, 2.62, 2.67, 2.71, 2.76, 2.81, 2.86, 2.92, 2.97]

plt.figure(1)
plt.subplot(211)
plt.plot(year, pop)

plt.subplot(212)
plt.scatter(year, pop)
plt.show()

Adapted from: https://matplotlib.org/users/pyplot_tutorial.html

AnilRedshift
  • 7,937
  • 7
  • 35
  • 59
  • ooohhhh it works. I will read that link to understand pyplot. Thank you a lot. –  Jun 27 '17 at 00:06