当前位置: 首页>>代码示例>>Python>>正文


Python ggplot函数代码示例

本文整理汇总了Python中ggplot函数的典型用法代码示例。如果您正苦于以下问题:Python ggplot函数的具体用法?Python ggplot怎么用?Python ggplot使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ggplot函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: plot_weather_data

def plot_weather_data(turnstile_weather):
	"""
	Plot turnstile weather data
	"""

	# Subway ridership by time of day
	# Create pivot table with UNIT on one hand, and cummulative entries on the other
	df_time_of_day = turnstile_weather.loc[:, ['Hour', 'ENTRIESn_hourly']].groupby(['Hour'], as_index = False).sum()
	# Create plot
	df_time_of_day_plot = ggplot(df_time_of_day, aes('Hour'))
	df_time_of_day_plot = df_time_of_day_plot + geom_bar(aes(x = 'Hour', weight = 'ENTRIESn_hourly'), binwidth = 1) + scale_x_continuous(limits = (0, 23))

	# Subway ridership by subway station
	# Create pivot table with UNIT on one hand, and cummulative entries on the other
	df_subway_station = turnstile_weather.loc[:, ['UNIT', 'ENTRIESn_hourly']].groupby(['UNIT'], as_index = False).sum()
	# Create plot
	df_subway_station_plot = ggplot(df_subway_station, aes(x = 'UNIT'))
	df_subway_station_plot = df_subway_station_plot + geom_bar(aes(x = 'UNIT', weight ='ENTRIESn_hourly'))

	# Subway ridership, total
	# Create pivot table with DATEn on one hand, and entries on the other
	df_total = turnstile_weather.loc[:, ['DATEn', 'ENTRIESn_hourly']].groupby(['DATEn'], as_index = False).sum()
	# Convert DATEn column to proper datetime
	df_total['DATEn'] = pandas.to_datetime(df_total['DATEn'])
	df_total['DATEn'] = [d.date() for d in df_total['DATEn']]
	# Create plot
	df_total_plot = ggplot(df_total, aes('DATEn'))
	df_total_plot = df_total_plot + geom_bar(aes(x = 'DATEn', weight = 'ENTRIESn_hourly')) + scale_x_date()

	return df_time_of_day_plot, df_subway_station_plot, df_total_plot
开发者ID:roodvuur,项目名称:udacity,代码行数:30,代码来源:plot_weather_data.py

示例2: timeseriesplots

	def timeseriesplots(self):
		rawdat = importSPOD(datafolder, 1, minTime, maxTime)
		rawdat['timeStamp'] = pd.Series(pd.date_range(minTime, maxTime, freq='10s'), index=pd.date_range(minTime, maxTime, freq='10s')).resample('1s', fill_method = 'pad')

		font = {'weight' : 'bold',
		        'size'   : 6}
		mpl.rcParams['axes.xmargin'] = .25
		mpl.rc('font', **font)

		base = ggplot(aes(x='timeStamp', y='Base'), data=rawdat) +\
		   geom_line(color='blue') +\
		   ylab('Base Sensor (V)') +\
		   xlab('') + ylim(0,5.1) +\
		   scale_x_date(labels='%m/%d %H:00', breaks=date_breaks('6 hours'))
		   #   theme_matplotlib(mpl.rc('font', **font), matplotlib_defaults=False)
		ggsave(plot = base, filename = figfolder+'Base.png', width = 8, height = 3)

		remote = ggplot(aes(x='timeStamp', y='Remote'), data=rawdat) +\
		    geom_line(color='blue') +\
		    ylab('Remote Sensor (V)') +\
		    xlab('') + ylim(0,5.1) +\
		    scale_x_date(labels='%m/%d %H:00', breaks=date_breaks('6 hours'))
		#   theme_matplotlib(mpl.rc('font', **font), matplotlib_defaults=False)

		ggsave(plot = remote, filename = figfolder+'Remote.png', width = 8, height = 3)
开发者ID:dendisuhubdy,项目名称:benzine_leak_detection,代码行数:25,代码来源:leakdetection+(Dendi+Suhubdy's+conflicted+copy+2015-12-08).py

示例3: plot_sed

def plot_sed(tmp,phot = None, fname = None, ignore = None, err = None):
    '''
    make plots using ggplot
    '''
    wav = tmp.df.wav
    cols = list(tmp.df.columns[1:])
    if ignore is not None:
        for i in ignore:
            cols.remove(i)
    df_plot = pd.DataFrame({'log wav(um)':np.log10(wav),'log flux':np.log10(tmp.df.loc[:,cols[0]]),'template':[cols[0] for x in range(len(wav))]})
    for i in cols[1:]:
        df = pd.DataFrame({'log wav(um)':np.log10(wav),'log flux':np.log10(tmp.df.loc[:,i]),'template':[i for x in range(len(wav))]})
        df_plot = pd.concat([df_plot,df])
    if phot is None:
        plt_out=ggplot(df_plot,aes(x='log wav(um)',y='log flux',color='template'))+geom_line()
    elif err is None:
        if type(phot) != pd.Series:
            print('phot should be in pandas series')
        else:
            df_phot = ({'log wav(um)':np.log10(np.asarray([dict_wav[x] for x in phot.index])),
                        'log flux':np.log10(phot.values.astype(float)),
                        'template':['Data' for x in range(len(phot))]})
            plt_out=ggplot(df_phot,aes(x='log wav(um)', y='log flux',color='template'))+\
                    geom_point()+geom_line(df_plot)
    else:
        plt_out=ggplot(df_plot,aes(x='log wav(um)',y='log flux',color='template'))+\
        geom_line()+geom_point(data = df_phot)
    #if fname is None:
    #    fname = 'plot'
    #ggsave(plt_out,fname+'.pdf')
    self.sed = plt_out
开发者ID:CTJChen,项目名称:ctc_astropylib,代码行数:31,代码来源:assef_nnls.py

示例4: generateBathroomTilePlot

def generateBathroomTilePlot(bl_vs_change_json):
    df = pd.read_json(bl_vs_change_json)
    summary_regions = ['ctx-lh-parsorbitalis','ctx-rh-parsorbitalis','ctx-rh-lateralorbitofrontal',
                       'ctx-lh-lateralorbitofrontal','ctx-rh-frontalpole','ctx-rh-parstriangularis',
                       'ctx-lh-frontalpole','ctx-lh-parstriangularis','ctx-lh-caudalanteriorcingulate',
                       'ctx-rh-rostralmiddlefrontal','ctx-lh-caudalmiddlefrontal',
                       'ctx-rh-caudalanteriorcingulate','ctx-rh-rostralanteriorcingulate',
                       'ctx-lh-rostralmiddlefrontal','ctx-rh-caudalmiddlefrontal',
                       'ctx-lh-superiorparietal','ctx-rh-isthmuscingulate',
                       'ctx-lh-rostralanteriorcingulate','ctx-rh-parsopercularis',
                       'ctx-rh-superiorparietal','ctx-lh-parsopercularis',
                       'ctx-rh-medialorbitofrontal','ctx-lh-isthmuscingulate',
                       'ctx-lh-supramarginal','ctx-lh-inferiorparietal','ctx-rh-supramarginal',
                       'ctx-lh-superiorfrontal','ctx-rh-superiorfrontal','ctx-rh-middletemporal',
                       'ctx-lh-middletemporal','ctx-rh-inferiorparietal','ctx-rh-superiortemporal',
                       'ctx-lh-posteriorcingulate','ctx-lh-precuneus','ctx-lh-medialorbitofrontal',
                       'ctx-lh-superiortemporal','ctx-rh-posteriorcingulate','ctx-rh-precuneus']
    ordering = {x:i for i,x in enumerate(summary_regions)}
    rank_by = summary_regions # could take subset of cortical summary regions
    subjects = GROUPS['increasing_low']['N']
    df = df[df['rid'].isin(subjects)]

    baseline_keys = ["%s_bl" % _ for _ in rank_by]
    change_keys = ["%s_change" % _ for _ in summary_regions]
    df['rank'] = df[baseline_keys].mean(axis=1)

    keep_keys = ['rid', 'rank'] + change_keys
    df = df[keep_keys]
    df_long = pd.melt(df,id_vars=['rank'],value_vars=change_keys)

    # sort change
    df_long['variable'] = [_.replace('_change','') for _ in df_long['variable']]
    df_long['variable'] = ['%s_%s' % (str(ordering[_]).zfill(2),_) for _ in df_long['variable']]

    print ggplot(aes(x='variable',y='rank'),data=df_long)+geom_tile(aes(fill='value'))+theme(axis_text_x=element_text(angle=270,size=8), axis_text_y=element_text(size=6))
开发者ID:catfishy,项目名称:jagust,代码行数:35,代码来源:pvc_raw_mappings.py

示例5: wrapper

def wrapper(name):
    global pltsize
    Xt, Yt=loadData(name, 'train')
    Xv, Yv=loadData(name, 'validate')
    w = Train(Xt, Yt, 0)
    print 'Classification Error (TR): ', classifyErr(LRPredict(w, Xt), Yt, 0.5), name
    print 'Classification Error (VAL):: ',classifyErr(LRPredict(w, Xv), Yv, 0.5), name
    t1 = 'Classification Error vs Decision Boundary - ' + name + ': Training'
    t2 = 'Classification Error vs Decision Boundary - ' + name + ': Validation'
    plotCEDB(w, Xt, Yt, '')
    plotCEDB(w, Xv, Yv, '')
    t1 = 'Logistic Regression - ' + name + ': Training'
    t2 = 'Logistic Regression - ' + name + ': Validation'
    plotDecisionBoundary(w, Xt, Yt, LRPredict, [0.5], '')
    plotDecisionBoundary(w, Xv, Yv, LRPredict, [0.5], '')
    l = array(linspace(0,100,101))
    tErr, tClass, vErr, vClass = GridL(Xt, Yt, Xv, Yv, l)
    DF1 = pd.DataFrame({'TR': pd.Series(tClass), 'VAL': pd.Series(vClass), 'Lambda': pd.Series(l)})
    DF1 = pd.melt(DF1,id_vars=['Lambda'])
    DF2 = pd.DataFrame({'TR': pd.Series(tErr), 'VAL': pd.Series(vErr), 'Lambda': pd.Series(l)})
    DF2 = pd.melt(DF2,id_vars=['Lambda'])
    title1 = 'Classification Error vs Lambda - ' + name
    title2 = 'Logisitic Loss vs Lambda - ' + name
    print p1 = ggplot(DF1, aes(x='Lambda', y='value', color='variable')) + geom_line(size=4) + ggtitle('') + ylab('Error') + theme_matplotlib(rc=pltsize, matplotlib_defaults=False)
    print p2 = ggplot(DF2, aes(x='Lambda', y='value', color='variable')) + geom_line(size=4) + ggtitle('') + ylab('Error') + theme_matplotlib(rc=pltsize, matplotlib_defaults=False)
开发者ID:jeremyzyang,项目名称:mit_6867,代码行数:25,代码来源:problem1.py

示例6: lineplot_compare

def lineplot_compare(hr_by_team_year_sf_la_csv):
	#ggplot(data, aes(xvar, yvar, color=category_var))
	dataframe = pandas.read_csv(hr_by_team_year_sf_la_csv)
	gg = ggplot(dataframe, aes(x='yearID', y='HR', color='teamID'))

	#gives the plot with the two categories seperated from each other. 
	gg = ggplot(dataframe, aes(x='yearID', y='HR', color='teamID')) + geom_point() + geom_line()
开发者ID:HDking,项目名称:NYCsubwayDataset,代码行数:7,代码来源:ggplot.py

示例7: test_stat_vhabline_functions

def test_stat_vhabline_functions():
    def fn_x(x):
        return 1
    def fn_y(y):
        return 1
    def fn_xy(x, y):
        return 1

    gg = ggplot(aes(x='wt'), mtcars)
    # needs y aesthetic
    with assert_raises(GgplotError):
        print(gg + stat_abline(slope=fn_xy))
    # needs y aesthetic
    with assert_raises(GgplotError):
        print(gg + stat_abline(intercept=fn_xy))

    gg = ggplot(aes(x='wt', y='mpg'), mtcars)
    # Functions with 2 args, no problem
    print(gg + stat_abline(slope=fn_xy, intercept=fn_xy))

    # slope function should take 2 args
    with assert_raises(GgplotError):
        print(gg + stat_abline(slope=fn_x, intercept=fn_xy))

    # intercept function should take 2 args
    with assert_raises(GgplotError):
        print(gg + stat_abline(slope=fn_xy, intercept=fn_y))

    # intercept function should take 1 arg
    with assert_raises(GgplotError):
        print(gg + stat_vline(xintercept=fn_xy))

    # intercept function should take 1 arg
    with assert_raises(GgplotError):
        print(gg + stat_hline(yintercept=fn_xy))
开发者ID:2dpodcast,项目名称:ggplot,代码行数:35,代码来源:test_stat_calculate_methods.py

示例8: test_stat_function

def test_stat_function():
    np.random.seed(7776)
    dnorm = lambda x : (1.0 / np.sqrt(2 * np.pi)) * (np.e ** (-.5 * (x ** 2)))
    print(ggplot(DataFrame({'x':np.random.normal(size=100)}),aes(x='x')) + \
              geom_density() + \
              stat_function(fun=dnorm,n=200))
    print(ggplot(DataFrame({'x':np.arange(10)}),aes(x='x')) + \
              stat_function(fun=np.sin,color="red") + \
              stat_function(fun=np.cos,color="blue"))
    # Test when args = list
    def to_the_power_of(n,p):
        return n ** p
    x = np.random.randn(100)
    y = x ** 3
    y += np.random.randn(100)
    data = DataFrame({'x':x,'y':y})
    print(ggplot(aes(x='x',y='y'),data) + geom_point() + \
              stat_function(fun=to_the_power_of,args=[3]))
    # Test when args = dict
    def dnorm(x,mean,var):
        return scipy.stats.norm(mean,var).pdf(x)
    data = DataFrame({'x':np.arange(-5,6)})
    print(ggplot(aes(x='x'),data=data) + \
        stat_function(fun=dnorm,color="blue",args={'mean':0.0,'var':0.2})   + \
        stat_function(fun=dnorm,color="red",args={'mean':0.0,'var':1.0})    + \
        stat_function(fun=dnorm,color="yellow",args={'mean':0.0,'var':5.0}) + \
        stat_function(fun=dnorm,color="green",args={'mean':-2.0,'var':0.5}))
开发者ID:IanSMcCarthy,项目名称:ggplot,代码行数:27,代码来源:test_stat_function.py

示例9: plot_year_doy

def plot_year_doy(df, title, palette='RdYlGn'):
    """ Plot year / doy with clear percent as color if available"""

    if 'clear' in df.columns:
        pct_clear = ((df['clear'] // 20) * 20).astype(np.uint8)
        df['Percent Clear'] = [' ' * (3 - len(str(v))) + str(v) 
                               if v < 100 else str(v) 
                               for v in pct_clear]

        # HACK to get all values shown
        need = ['  0', ' 20', ' 40', ' 60', ' 80', '100']
        to_add = [v for v in need if v not in np.unique(df['Percent Clear'])]
        for v in to_add:
            df = pd.concat([df, df[:1]])
            df['year'][-1:] = np.nan
            df['doy'][-1:] = np.nan
            df['Percent Clear'][-1:] = v

        plot = ggplot(aes('year', 'doy', color='Percent Clear'), df)
        plot = plot + scale_color_brewer(type='diverging', palette=palette)

    else:
        plot = ggplot(aes('year', 'doy'), df)

    return(plot + geom_point(size=50) +
           xlim(df.year.min() - 1, df.year.max() + 1) +
           ylim(0, 366) +
           xlab('Year') +
           ylab('Day of Year') +
           ggtitle(title))
开发者ID:ceholden,项目名称:misc,代码行数:30,代码来源:plot_stack_nobs.py

示例10: plotHist

def plotHist(arr, category, save_dir):

    def space2Highfen(string):
        if ' ' in string:
            print('{0} has space\n'.format(string))
            strList = list(string)
            length = len(strList)
            for i in range(length):
                if strList[i] == ' ':
                    strList[i] = '-'
            return ''.join(strList)
        return string

    arr = [x for x in arr if x != 0]
    maxi = max(arr)
    col1 = 'original-'+space2Highfen(category)
#   col2 = 'linear-'+category
#   col3 = 'log-'+category
    col4 = 'log-Scale-'+space2Highfen(category)
    df = pd.DataFrame(pd.Series(arr), columns = [col1]) #original
#   df[col2] = (maxi - df[col1])/maxi
#   df[col3] = (np.log(maxi) - np.log(df[col1]))/np.log(maxi)
    df[col4] = np.log(df[col1])                         #logscale

    width = 6
    height = 5.5
    p1 = ggplot(aes(x = col1), data = df) + geom_histogram()
#   p2 = ggplot(aes(x = col2), data = df) + geom_histogram()
#   p3 = ggplot(aes(x = col3), data = df) + geom_histogram()
    p4 = ggplot(aes(x = col4), data = df) + geom_histogram()
    ggsave(plot = p1, filename = col1 + ".png", path = save_dir, width = width, height = height, dpi = 75) # reduce dpi to save compile time
#   ggsave(plot = p2, filename = col2 + "no0.png", path = save_dir)
#   ggsave(plot = p3, filename = col3 + "no0.png", path = save_dir)
#   ggsave(plot = p4, filename = col4 + ".png", path = save_dir, width = 5, height = 5, dpi = 100)
    ggsave(plot = p4, filename = col4 + ".png", path = save_dir, width = width, height = height, dpi = 75)
开发者ID:yujiex,项目名称:energyMap,代码行数:35,代码来源:util_loadData.py

示例11: test_geom_rect

def test_geom_rect():
    df = pd.DataFrame({
        'xmin': [1,3,5],
        'xmax': [2, 3.5, 7],
        'ymin': [1, 4, 6],
        'ymax': [5, 5, 9],
        'fill': ['blue', 'red', 'green'],
        'quality': ['good', 'bad', 'ugly'],
        'alpha': [0.1, 0.5, 0.9],
        'texture': ['hard', 'soft', 'medium']})
    p = ggplot(df, aes(xmin='xmin', xmax='xmax', ymin='ymin', ymax='ymax',
               colour='quality', fill='fill', alpha='alpha',
               linetype='texture'))
    p += geom_rect(size=5)
    assert_same_ggplot(p, 'geom_rect')

    p = ggplot(df, aes(xmin='xmin', xmax='xmin + 1', ymin='ymin',
               ymax='ymin + 1'))
    p += geom_rect()
    assert_same_ggplot(p, 'geom_rect_plus')

    p = ggplot(df, aes(x='xmin', y='ymin'))
    p += geom_point(size=100, colour='red', alpha=0.5)
    p += geom_rect(aes(fill='fill', xmin='xmin', xmax='xmin + 1', ymin=0,
                   ymax='ymax'), alpha=0.1)
    assert_same_ggplot(p, 'geom_rect_with_point')
开发者ID:JasonKessler,项目名称:ggplot,代码行数:26,代码来源:test_basic.py

示例12: aggregate_by_month

def aggregate_by_month(coll):
    data = [x for x in coll.find()]
    index = [datetime.strptime(x['created']['timestamp'], DT_FRMT) for x in data]
    df = pd.DataFrame(dict(month=[month(x) for x in index], count=[1 for x in index]), index=index)
    month_count = df.groupby('month', as_index=False).aggregate(np.count_nonzero)
    print month_count
    print ggplot(aes(x='month', y='count'), data=month_count) + geom_bar(stat='identity') + labs(title='By Count') + ylab('Num Records')
开发者ID:jaybaker,项目名称:wrangle.mongodb,代码行数:7,代码来源:explore.py

示例13: test_scale

def test_scale():
    meat = _build_meat_df()
    p = ggplot(aes(x='date', y='beef'), data=meat)
    print(p + geom_point() + scale_x_continuous("This is the X") + scale_y_continuous("Squared", limits=[0, 1500]))
    print(p + geom_point() + ylim(0, 1500))
    gg = ggplot(aes(x='date', y='beef'), data=meat) + geom_line() 
    print(gg+scale_x_date(labels="%Y-%m-%d"))
开发者ID:hernamesbarbara,项目名称:ggplot,代码行数:7,代码来源:test_basic.py

示例14: main

def main():
    # Set system variables
    root = r'/Users/DC-MBP/Desktop/final-project'
    temp = os.path.join(root, 'Temp')
    data = r'/Users/DC-MBP/Desktop/yelp-api'
    data_file = 'yelp_academic_dataset_business.json'

    # Set regression formula
    rf = 'stars ~ review_count + state + Caters + Attire + BYOB + Alcohol'

    # Create data file
    df_business = process_data_restaurant(data, data_file)
    
    # Create Vegas data file
    #create distance from town center 36.175, -115.136389
    df_vegas = df_business[df_business.city == "Las Vegas"]
    df_vegas['distance'] = np.sqrt(np.power(df_vegas.latitude-36.175,2) +
                                   np.power(df_vegas.longitude+115.136389,2))
    
    # Create visualizations
    p1 = ggplot(aes(y='stars', x='review_count'),data=df_business)
    print(p1 + geom_point())
    
    p2 = ggplot(aes(y='latitude', x='longitude'), data=df_vegas)
    print(p2 + geom_point())
    
    p3 = ggplot(aes(y='stars', x='distance'), data=df_vegas)
    print(p3 + geom_point())
    
    print 'End'
开发者ID:ajschumacher,项目名称:gadsdc2,代码行数:30,代码来源:dc_create_graphs.py

示例15: main

def main(parameters):
    label = sys.argv[-1]   # Sumatra appends the label to the command line
    subdir = os.path.join("mydata", label)
    #os.mkdir(subdir)

    res = {}
    an = []
    ax = []
    ay = []
    
    all_df = pd.DataFrame({"i":[],"Name":[]})
    
    final_df = pd.DataFrame({"Algorithm":[],"Task":[],"Steps":[]})

    for scenario in parameters["scenarios"]:
        res[scenario] = {}
        for algorithm in parameters["algorithms"]:
            name = scenario+"_"+algorithm
            fileid = "%s_%s.txt" % (scenario, algorithm)
            fn = os.path.join(subdir, fileid)
            da, ap = average_run(parameters["AcceptableScore"],fn)
            for i,r in ap.iterrows():
                an.append(name)
                ax.append(r["n"])
                ay.append(r["avg"])
                
            
            all_df = all_df.append(da)
            #print algorithm,ax,ay, ap
#            if len(ay) == 0:
                
            final_df = final_df.append(dict(Algorithm=algorithm,Task=scenario,Steps=ay[-1]),ignore_index=True)
                
    # showing that we have enough runs
    df = pd.DataFrame({"Name":an,"Runs":ax,"Avg":ay})
    #print df
    p = ggplot(aes(x='Runs',y="Avg"), data=df) + geom_point() + geom_line()+ \
    facet_wrap("Name")
    ggsave(p,os.path.join(subdir, "avg_runs.png"))
    
    
    #ploting all runs
    #all_df["y"] = all_df["0"]
    #print all_df
    all_plot = ggplot(aes(x='i', y='avg',colour="Name"), data=all_df) + geom_point() + geom_line()
    ggsave(all_plot,os.path.join(subdir, "all_runs.png"))

    #final comparison
    #do in R
    #print final_df
    final_df.to_csv(os.path.join(subdir, "final_comp.csv"),index=False)
    
    
    import subprocess
    proc = subprocess.Popen(['/usr/bin/Rscript','result.R',subdir], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = proc.communicate()
    print stdout,stderr
    proc.wait()
    print "done",subdir
开发者ID:nairboon,项目名称:bnrl,代码行数:59,代码来源:analysis.py


注:本文中的ggplot函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。