예제 #1
0
from plot_tools.dotplot import dotplot

font = 'Serif'
caption = 'Festing on Protien (AARP Bulletin, Sept. 2009)'

data = {
    '1 - 1.9': 3,
    '2 - 2.9': 5,
    '3 - 3.9': 4,
    '4 - 4.9': 0,
    '5 - 5.9': 6,
    '6 - 6.9': 1
}

plt = dotplot([1, 2, 3, 4, 5, 6], list(data.values()))
plt.xticks([1, 2, 3, 4, 5, 6], labels=list(data.keys()), fontname=font)
plt.yticks([0, 1, 2, 3, 4, 5], labels=[1, 2, 3, 4, 5, 6], fontname=font)
plt.title('The Cost of Protien (per gram)', fontsize=14, fontname=font)
plt.xlabel('Cents', fontsize=10, fontname=font)
plt.ylabel('Number of Food Sources', fontsize=10, fontname=font)
plt.figtext(0.5,
            0.01,
            caption,
            wrap=True,
            ha='center',
            fontsize=8,
            fontname=font)
plt.gcf().set_size_inches(7, 6)
plt.axes().figure.set_facecolor('lightgrey')
plt.grid(color='lightgrey', alpha=0.3)
from plot_tools.dotplot import dotplot
import pandas as pd
import pathlib

font = 'Serif'
title = 'Violent Crime on College Campuses in Florida, 2012'
source = 'Source: The FBI web site'
filename = pathlib.Path(__file__)

df = pd.read_csv(filename.with_suffix('.csv'), index_col=0)
data = df['crimes']

plt = dotplot(list(range(16)), df['crimes'])
plt.xticks(list(range(16)),
           labels=df['school'],
           fontname=font,
           color='cyan',
           rotation=33)
plt.yticks(list(range(31)),
           labels=list(range(1, 32)),
           fontname=font,
           color='darkcyan')
plt.suptitle(title, fontsize=15, fontname=font, color='cyan')
plt.title(source, fontsize=8, fontname=font, color='darkcyan')
plt.ylabel('Number of Crimes', fontsize=10, fontname=font, color='purple')

plt.gcf().set_size_inches(13, 7)

ax = plt.axes()
ax.figure.set_facecolor('black')
ax.set_facecolor('black')
    Skip some x-axis labels
    '''
    labels = []
    for label in range(0, xmax):
        try:
            if not label % skip:
                labels.append(str(label))
            else:
                continue
                #labels.append(None)
        except ZeroDivisionError:
            labels.append(str(label))
    return labels


plt = dotplot(df[x_col], df[y_col], dcolor, dsize, ecolor, ewidth)
locs, labels = plt.xticks()
plt.xticks(locs, ['', '100', '200', '300', '400', '500', '600', '700', '800'],
           fontname=font,
           color=trim,
           rotation=x_rotation)
plt.yticks(list(range(y_len)),
           list(range(1, y_len + 1)),
           fontname=font,
           color=trim)
plt.suptitle(title, fontsize=15, fontname=font, color=bold)
plt.title(source, fontsize=8, fontname=font, color=trim)
plt.ylabel(ylabel, fontsize=10, fontname=font, color=bold)
plt.xlabel(xlabel, fontsize=10, fontname=font, color=bold)
plt.gcf().set_size_inches(x_size, y_size)
plt.grid(color=grid, alpha=alpha)
예제 #4
0
color = 'royalblue'


def xlabels():
    labels = []
    for label in range(0, 46):
        if not label % 5:
            labels.append(label)
        else:
            labels.append(None)
    return labels


df = pd.read_csv(filename.with_suffix('.csv'))

plt = dotplot(df['%'], df['freq'])
plt.xticks(list(range(46)),
           labels=xlabels(),
           fontname=font,
           color='black',
           rotation=0)
plt.yticks(list(range(10)),
           labels=list(range(1, 11)),
           fontname=font,
           color='black')
plt.suptitle(title, fontsize=15, fontname=font, color='darkblue')
plt.title(source, fontsize=8, fontname=font, color='black')
plt.ylabel('Number of Beaches', fontsize=10, fontname=font, color='darkblue')
plt.xlabel('Percentage of Failed Tests',
           fontsize=10,
           fontname=font,