1

I have this dataset, where columns are values across the years and rows values in Sterling Pounds:

         total_2013  total2014  total_2015  total_2016
0         1569000    1614000     1644000     1659000
1          330000     423000      474000      540000
2         2100000    2080000     2093000     2135000
3         2161000    2238000     2221000     2200000
4         1865000    1975000     2046000     2152000
5         1903000    1972000     1970000     2034000
6         2087000    2091000     1963000     1956000
7         1237000    1231000     1199000     1188000
8         1043000    1072000     1076000     1059000
9          569000     610000      564000      592000
10        2207000    2287000     2191000     2274000
11        1908000    1908000     1917000     1908000

I need to plot in the X-axis the columns total_2013, total_2014, total_2015, total_2016.

In the Y-axis, I need to draw a point for the single values of each row and draw a line between these values along the years 2013-2016.

I couldn't make work xticks to put the values in the columns as different time points in the X-axis. Not sure if that's the right thing to do neither.

I have plotted so far this:

import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
matplotlib.style.use('ggplot')
ax = data_merged_years.plot(kind='line', title ="UK Schools budget per year 2013-2016", figsize=(15, 10), legend=True, fontsize=12)
ax.set_xlabel("Year", fontsize=12)
ax.set_ylabel("Pounds", fontsize=12)
plt.show()

My attempt: Wrong plot with incorrect X and Y:
My attempt: Wrong plot with incorrect X and Y

1
  • I'm not sure I understand your dataset. What are the contents of the rows? As far as I understand right now there's one dimension too many. Commented Feb 27, 2017 at 12:38

1 Answer 1

2

With your script the output I can produce is this: enter image description here

If you want the columns as x-axis rather than different lines you could transpose the DataFrame before plotting:

In [13]: import matplotlib.pyplot as plt
    ...: import pandas as pd
    ...: matplotlib.style.use('ggplot')
    ...: ax = data_merged_years.transpose().plot(kind='line', title ="UK Schools budget per year 2013-2016", figsize=(15, 10), legend=True, fontsize=12)
    ...: ax.set_xlabel("Year", fontsize=12)
    ...: ax.set_ylabel("Pounds", fontsize=12)
    ...: plt.show()
    ...: 

enter image description here

From your original plot it seems that you would have over ten thousand lines in one plot. Are you sure that is what you want?

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

1 Comment

transpose worked well. I simplified to data_merged_years.transpose().plot() plt.show()and showed the labels well. Can't plot the 20,000 rows I have (error: too large) but the original purpose was to apply this in smaller data subsets.

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.