Пример #1
0
def main(script):

    MakeChangePlot()

    options = dict(linewidth=3, markersize=0, alpha=0.7)
    data = ReadData('heri14.csv')

    # plot nones

    nones = GetColumn(data, 1)
    # del nones[1966]
    ts, ys = RenderColumn(nones)

    MakePlot(ts, ys, model='ys ~ ts + t2')

    pyplot.plot(ts, ys, 'bs-', label='No religion', **options)
    
    # add the actual value from 2014
    thinkplot.Plot([2014], [27.5], 'bs')

    thinkplot.Save(root='heri14.1',
                formats=FORMATS,
                ylabel='Percent',
                loc=2,
                axis=[1967, UPPER, 0, 30])


    # plot attendance

    attendance = GetColumn(data, 4)
    del attendance[1966]
    ts, ys = RenderColumn(attendance)
    ys = [100-y for y in ys]

    MakePlot(ts, ys, model='ys ~ ts + t2')

    pyplot.plot(ts, ys, 'go-', label='No attendance', **options)

    # add the actual value from 2014
    thinkplot.Plot([2014], [100 - 70.7], 'gs')

    thinkplot.Save(root='heri14.2',
                formats=FORMATS,
                ylabel='Percent',
                loc=2,
                axis=[1967, UPPER, 0, 30])

    MakeGenderPlot()
Пример #2
0
def MakeChangePlot(filename='heri15.csv'):
    """Generates a plot with the data, a fitted model, and error bars."""
    pyplot.clf()

    data = ReadData(filename)
    print data

    no_rel = GetColumn(data, 1)
    ts, ys = RenderColumn(no_rel)

    ts = ts[11:]
    ys = ys[10:]
    ds = numpy.diff(ys)
    print len(ts)
    print len(ys)
    print len(ds)
    MakePlot(ts, ds, model='ys ~ ts')

    options = dict(linewidth=3, markersize=0, alpha=0.7)
    pyplot.plot(ts,
                ds,
                color='purple',
                label='Change in no religion',
                **options)

    thinkplot.Save(root='heri15.5',
                   formats=FORMATS,
                   ylabel='Percentage points',
                   loc=2,
                   axis=[1986, UPPER, -3, 3])
Пример #3
0
def MakeGenderPlot(filename='heri15.csv'):
    """Generates a plot with the data, a fitted model, and error bars."""
    pyplot.clf()

    data = ReadData(filename)

    men = GetColumn(data, 6)
    ts, ys = RenderColumn(men)
    pyplot.plot(ts, ys, 'b-', linewidth=3, alpha=0.7, label='men')

    women = GetColumn(data, 11)
    ts, ys = RenderColumn(women)
    pyplot.plot(ts, ys, 'g-', linewidth=3, alpha=0.7, label='women')

    thinkplot.Save(root='heri15.3',
                   formats=FORMATS,
                   title='',
                   xlabel='',
                   ylabel='Preferred religion None (%)',
                   axis=[1967, UPPER, 0, 28])

    del men[1969]
    del women[1969]
    ts, ds = DiffColumns(men, women)

    MakePlot(ts, ds, model='ys ~ ts')

    pyplot.plot(ts,
                ds,
                color='purple',
                linewidth=3,
                alpha=0.7,
                label='Gender gap')

    thinkplot.Save(root='heri15.4',
                   formats=FORMATS,
                   title='',
                   xlabel='',
                   ylabel='Percentage points',
                   axis=[1967, UPPER, 0, 6])