1

thanks for your time & feedback, could not find any previous questions or documentation on this issue.

Goal: I'm trying to graph data about the G7 countries (plus Russia & China) using matplotlib subplots. The end result is six subplots of displaying various population, GDP, and military expenditure data.

Problem: There appears to be some sort of extra text colliding with some of the subplot titles and I can neither figure out what the extra text is or how to remove it.

Notice the extra text colliding with the Real GDP plot & Population plot plot

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.ticker as mtick
%matplotlib notebook

#import csv, check output
data = pd.read_csv('MATPLOTLIB Practice\G7+2_2019.csv', 
                   index_col=0,
                   dtype={'POPULATION': int, 
                          'GDP': np.int64, 
                          'GPD PER CAPITA': int, 
                          'GDP GROWTH RATE': np.float64, 
                          'MILITARY EXPENDITURE PER GDP': np.float64, 
                          'Est MIL EXPENDITURE': np.int64},
                  )
data
#assign column variable names for future plots
POP = data['POPULATION']
GDP = data['GDP']
GDP_per_capt = data['GDP PER CAPITA']
GDP_GROWTH = data['GDP GROWTH RATE']
MIL_EXP_PER_GDP = data['MILITARY EXPENDITURE PER GDP']
MIL_EXP = data['Est MIL EXPENDITURE']

#create plot label properties
GDP_prop = {'xlabel': '', 'ylabel': 'Tens of Trillions'}
GDP_pcap_prop ={'xlabel': '', 'ylabel': '2010 Dollars'}
GDP_growth_prop = {'xlabel': '', 'ylabel': '% of GDP', 'yticks': [0, 1, 2, 3, 4, 5, 6, 7]}
pop_prop = {'xlabel': '', 'ylabel': 'Billions of people'}
mil_exp_pgdp_prop = {'xlabel': '', 'ylabel': '% of GDP'}
mil_expenditure_prop ={'xlabel': '', 'ylabel': '100s of Billions\n in 2010 $', 'yticks': [0, 300, 600, 900]}

#Create figure, axes, & subplots.
fig = plt.figure()

ax1 = fig.add_subplot(2, 3, 1, title='Real GDP')
ax2 = fig.add_subplot(2, 3, 2, title='GDP Per Capita')
ax3 = fig.add_subplot(2, 3, 3, title='GPD Growth Rate')
ax4 = fig.add_subplot(2, 3, 4, title='Population')
ax5 = fig.add_subplot(2, 3, 5, title='Military Exp Per GDP')
ax6 = fig.add_subplot(2, 3, 6, title='Est Military Expenditure')

GDP.plot.bar(ax=ax1, color='#2e856e', )
GDP_per_capt.plot.bar(ax=ax2, color='#2e856e')
GDP_GROWTH.plot.bar(ax=ax3, color='#2e856e')
POP.plot.bar(ax=ax4)
MIL_EXP_PER_GDP.plot.bar(ax=ax5, color='#f2003c')
MIL_EXP.plot.bar(ax=ax6, color='#f2003c')
                
    
#tie in plot label properties    
ax1.set(**GDP_prop)
ax2.set(**GDP_pcap_prop)
ax3.set(**GDP_growth_prop)
ax4.set(**pop_prop)
ax5.set(**mil_exp_pgdp_prop)
ax6.set(**mil_expenditure_prop)

fig.tight_layout(h_pad=2)

below is the data from the csv

COUNTRY,POPULATION,GDP,GDP PER CAPITA,GDP GROWTH RATE,MILITARY EXPENDITURE PER GDP,Est MIL EXPENDITURE
CHINA,1398000000,14327359000000,16117,6.14,1.90,272
RUSSIA,144400000,1702361000000,27044,1.34,4.00,68
US,328200000,21433228000000,62530,2.16,3.73,799
UK,66650000,2827918000000,46659,1.26,2.32,66
CANADA,37590000,1741865000000,49031,1.66,1.42,25
FRANCE,67060000,2715574000000,46184,1.49,2.04,55
GERMANY,83020000,4482448000000,53919,1.45,1.56,70
ITALY,60360000,2002763000000,42492,0.034,1.39,28
JAPAN,126300000,5078679000000,41429,0.70,1.00,51
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
jpank
  • 13
  • 3

0 Answers0