0

I want to write a code in python (using pandas and matplotlib) to illustrate many trends in a single window. My initial dataset is something like this:

  • NO. Year Position Year Position Year Position
  • 1 2000 1 2002 2 2005 3

  • 2 1999 2 2003 2 2006 3

    ...

  • 40 1999 3 2005 2 2007 1

In fact, each data point (1,2,3...40) has different positions between 1-3 in different years. I just want to show the trend of their positions. Probably it should be a simple line chart for each of them. And I want to show all of the charts in a single window so that we can compare the results of different data points' trends. Any idea where should I start? Thanks in advance for your help.

  • 1
    Can you provide more details about your data and the plot you would create? – PieCot Jun 17 '18 at 18:04
  • Hi. Each data point (1,2,3...40) has different positions between 1-3 in different years. I just want to show the trend of their positions. Probably it should be a simple line chart for each of them. And I want to show all of the charts in a single window so that we can compare the results of different data points' trends. – Mehrdad Fonooni Jun 17 '18 at 18:11
  • 1
    So which is the question here? You told us what you want, but where are you struggling? You dont know which framework to use? You dont know how to use it? You dont know where to start? Depending on which the question is too broad. – Imanol Luengo Jun 17 '18 at 18:22
  • Imanol you're right. I'm trying to use matplotlib and pandas to write the code. Still don't know where to start. I know how to write a code for two datasets (such as two columns of X and Y) but here I have a trend of more than 2 datasets for each number. – Mehrdad Fonooni Jun 17 '18 at 18:30

1 Answers1

1

Suppose that df is your dataframe, you can use this code as a starting point:

import pylab as plt
plt.figure("Unknown index")
for i, (name, row) in enumerate(df.iterrows()):
    x, y = row[0::2], row[1::2]
    plt.plot(x, y, '-*', label='Trend {}'.format(i))
plt.xticks(list(range(2000, 2017)))

plt.legend(loc=1)
plt.show()
PieCot
  • 3,564
  • 1
  • 12
  • 20