Skip to content

Instantly share code, notes, and snippets.

@bkamapantula
Created October 19, 2014 18:24
Show Gist options
  • Save bkamapantula/25a931bedd76ffabab74 to your computer and use it in GitHub Desktop.
Save bkamapantula/25a931bedd76ffabab74 to your computer and use it in GitHub Desktop.
Boxplot in python using pandas, matplotlib | Vary position of figure
import pandas as pd
import matplotlib.pyplot as plt
import sys
import os
import matplotlib as mpl
pd.options.display.mpl_style = 'default'
def box_plot():
f = open(sys.argv[1], "r")
image_name = os.path.splitext(sys.argv[1])[0]+".pdf"
vals = pd.DataFrame.from_csv(f, sep='\t', index_col=False) #, columns=['20'])
fig = plt.figure();
ax = fig.add_subplot(111)
bp = vals.boxplot()
plt.xlabel('Loss (%)')
plt.ylabel('Packet receipt rate (%)')
# sets font size
font = {'family' : 'normal',
'weight' : 'bold',
'size' : 18}
mpl.rc('font', **font)
# gets axes position
fig_pos = ax.get_position()
# sets axes position; done to move figure vertically
ax.set_position([fig_pos.x0, fig_pos.y0+0.045, fig_pos.width, fig_pos.height])
plt.savefig(image_name, format='pdf')
box_plot()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment