コード例 #1
0
ファイル: tm_tools.py プロジェクト: nudtchengqing/time-maps
def make_heated_time_map(sep_array, Nside, width):

	print 'generating heated time map ...'
	
	# choose points within specified range. Example plot separations greater than 5 minutes:
#	indices = (sep_array[:,0]>5*60) & (sep_array[:,1]>5*60)
	indices=range(sep_array.shape[0]) # all time separations

	x_pts = np.log(sep_array[indices,0])
	y_pts = np.log(sep_array[indices,1])

	min_val = np.min([np.min(x_pts), np.min(y_pts)])
	
	x_pts = x_pts - min_val
	y_pts = y_pts - min_val
	
	max_val = np.max([np.max(x_pts), np.max(y_pts)])
	
	x_pts *= (Nside-1)/max_val
	y_pts *= (Nside-1)/max_val
	
	img=np.zeros((Nside,Nside))

	for i in range(len(x_pts)):

		img[x_pts[i],y_pts[i]] +=1

	img = ndi.gaussian_filter(img,width) # apply Gaussian filter
	
	img = np.sqrt(img) # taking the square root makes the lower values more visible

	img=np.transpose(img) # needed so the orientation is the same as scatterplot

	plt.imshow(img, origin='lower')
	
	## create custom tick marks. Calculate positions of tick marks on the transformed log scale of the image array
	
	plt.minorticks_off()
	
	## change font, which can also now accept latex: http://matplotlib.org/users/usetex.html
	plt.rc('text',usetex=True)
	plt.rc('font',family='serif')

	my_max = np.max([np.max(sep_array[indices,0]), np.max(sep_array[indices,1])])
	my_min = np.max([np.min(sep_array[indices,0]), np.min(sep_array[indices,1])])

	pure_ticks = np.array([1e-3,1,10,60*10,2*3600,1*24*3600, 7*24*3600])         # where the tick marks will be placed, in units of seconds. An additional value will be appended to the end for the max
	labels = ['1 msec','1 sec','10 sec','10 min','2 hr','1 day','1 week']  # tick labels

	index_lower=np.min(np.nonzero(pure_ticks >= my_min)) # index of minimum tick that is greater than or equal to the smallest time interval. This will be the first tick with a non-blank label
	
	index_upper=np.max(np.nonzero(pure_ticks <= my_max))
	
	ticks = pure_ticks[index_lower: index_upper + 1]
	ticks = np.log(np.hstack((my_min, ticks, my_max ))) # append values to beginning and end in order to specify the limits
	ticks = ticks - min_val
	ticks *= (Nside-1)/(max_val)
	
	labels= np.hstack(('',labels[index_lower:index_upper + 1],'')) # append blank labels to beginning and end
	
	plt.xticks(ticks, labels,fontsize=16)
	plt.yticks(ticks, labels,fontsize=16)

	plt.xlabel('Time Before Tweet',fontsize=18)
	plt.ylabel('Time After Tweet' ,fontsize=18)
	
	plt.show()

	return None
コード例 #2
0
ファイル: tm_tools.py プロジェクト: nudtchengqing/time-maps
def make_time_map(times, times_tot_mins, sep_array, Ncolors):

	print 'rendering normal time map ...'
	
	## set up color list
	
	red=Color("red")
	blue=Color("blue")
	color_list = list(red.range_to(blue, Ncolors)) # range of colors evenly speced on the spectrum between red and blue. Each element is a colour object
	color_list = [c.hex for c in color_list] # give hex version
		
	fig=plt.figure()
	ax =fig.add_subplot(111)
	
	plt.rc('text',usetex=True)
	plt.rc('font',family='serif')
	
	colormap = plt.cm.get_cmap('rainbow')  # see color maps at http://matplotlib.org/users/colormaps.html
	
	order=np.argsort(times_tot_mins[1:-1]) # so that the red dots are on top
#	order=np.arange(1,len(times_tot_mins)-2) # dots are unsorted

	# taken from http://stackoverflow.com/questions/6063876/matplotlib-colorbar-for-scatter
	
	sc= ax.scatter(sep_array[:,0][order],sep_array[:,1][order],c=times_tot_mins[1:-1][order],vmin=0,vmax=24*60,s=25,cmap=colormap,marker='o',edgecolors='none')
	
	color_bar=fig.colorbar(sc,ticks=[0,24*15,24*30,24*45,24*60],orientation='horizontal',shrink=0.5)
	color_bar.ax.set_xticklabels(['Midnight','18:00','Noon','6:00','Midnight'])
	color_bar.ax.invert_xaxis()
	color_bar.ax.tick_params(labelsize=16)
	
	ax.set_yscale('log') # logarithmic axes
	ax.set_xscale('log')
	
	plt.minorticks_off()
	
	pure_ticks = np.array([1e-3,1,10,60*10,2*3600,1*24*3600, 7*24*3600]) # where the tick marks will be placed, in units of seconds.
	labels = ['1 msec','1 sec','10 sec','10 min','2 hr','1 day','1 week']  # tick labels
	
	max_val = np.max([np.max(sep_array[:,0]), np.max(sep_array[:,1])])
	
	ticks = np.hstack((pure_ticks, max_val))
	
	min_val = np.min([np.min(sep_array[:,0]), np.min(sep_array[:,1])])
	
	plt.xticks(ticks,labels,fontsize=16)
	plt.yticks(ticks,labels,fontsize=16)
	
	plt.xlabel('Time Before Tweet',fontsize=18)
	plt.ylabel('Time After Tweet',fontsize=18)
	
	plt.xlim((min_val, max_val))
	plt.ylim((min_val, max_val))
	
	ax.set_aspect('equal')
	
	plt.tight_layout()
	
	plt.show()

	return None
コード例 #3
0
ファイル: tm_tools.py プロジェクト: springcoil/time-maps
def make_heated_time_map(sep_array, Nside, width):

    print 'generating heated time map ...'

    # choose points within specified range. Example plot separations greater than 5 minutes:
    #	indices = (sep_array[:,0]>5*60) & (sep_array[:,1]>5*60)
    indices = range(sep_array.shape[0])  # all time separations

    x_pts = np.log(sep_array[indices, 0])
    y_pts = np.log(sep_array[indices, 1])

    min_val = np.min([np.min(x_pts), np.min(y_pts)])

    x_pts = x_pts - min_val
    y_pts = y_pts - min_val

    max_val = np.max([np.max(x_pts), np.max(y_pts)])

    x_pts *= (Nside - 1) / max_val
    y_pts *= (Nside - 1) / max_val

    img = np.zeros((Nside, Nside))

    for i in range(len(x_pts)):

        img[x_pts[i], y_pts[i]] += 1

    img = ndi.gaussian_filter(img, width)  # apply Gaussian filter

    img = np.sqrt(
        img)  # taking the square root makes the lower values more visible

    img = np.transpose(
        img)  # needed so the orientation is the same as scatterplot

    plt.imshow(img, origin='lower')

    ## create custom tick marks. Calculate positions of tick marks on the transformed log scale of the image array

    plt.minorticks_off()

    ## change font, which can also now accept latex: http://matplotlib.org/users/usetex.html
    plt.rc('text', usetex=True)
    plt.rc('font', family='serif')

    my_max = np.max(
        [np.max(sep_array[indices, 0]),
         np.max(sep_array[indices, 1])])
    my_min = np.max(
        [np.min(sep_array[indices, 0]),
         np.min(sep_array[indices, 1])])

    pure_ticks = np.array(
        [1e-3, 1, 10, 60 * 10, 2 * 3600, 1 * 24 * 3600, 7 * 24 * 3600]
    )  # where the tick marks will be placed, in units of seconds. An additional value will be appended to the end for the max
    labels = [
        '1 msec', '1 sec', '10 sec', '10 min', '2 hr', '1 day', '1 week'
    ]  # tick labels

    index_lower = np.min(
        np.nonzero(pure_ticks >= my_min)
    )  # index of minimum tick that is greater than or equal to the smallest time interval. This will be the first tick with a non-blank label

    index_upper = np.max(np.nonzero(pure_ticks <= my_max))

    ticks = pure_ticks[index_lower:index_upper + 1]
    ticks = np.log(np.hstack(
        (my_min, ticks, my_max)
    ))  # append values to beginning and end in order to specify the limits
    ticks = ticks - min_val
    ticks *= (Nside - 1) / (max_val)

    labels = np.hstack(('', labels[index_lower:index_upper + 1],
                        ''))  # append blank labels to beginning and end

    plt.xticks(ticks, labels, fontsize=16)
    plt.yticks(ticks, labels, fontsize=16)

    plt.xlabel('Time Before Tweet', fontsize=18)
    plt.ylabel('Time After Tweet', fontsize=18)

    plt.show()

    return None
コード例 #4
0
ファイル: tm_tools.py プロジェクト: springcoil/time-maps
def make_time_map(times, times_tot_mins, sep_array, Ncolors):

    print 'rendering normal time map ...'

    ## set up color list

    red = Color("red")
    blue = Color("blue")
    color_list = list(
        red.range_to(blue, Ncolors)
    )  # range of colors evenly speced on the spectrum between red and blue. Each element is a colour object
    color_list = [c.hex for c in color_list]  # give hex version

    fig = plt.figure()
    ax = fig.add_subplot(111)

    plt.rc('text', usetex=False)
    plt.rc('font', family='serif')

    colormap = plt.cm.get_cmap(
        'rainbow'
    )  # see color maps at http://matplotlib.org/users/colormaps.html

    order = np.argsort(times_tot_mins[1:-1])  # so that the red dots are on top
    #	order=np.arange(1,len(times_tot_mins)-2) # dots are unsorted

    # taken from http://stackoverflow.com/questions/6063876/matplotlib-colorbar-for-scatter

    sc = ax.scatter(sep_array[:, 0][order],
                    sep_array[:, 1][order],
                    c=times_tot_mins[1:-1][order],
                    vmin=0,
                    vmax=24 * 60,
                    s=25,
                    cmap=colormap,
                    marker='o',
                    edgecolors='none')

    color_bar = fig.colorbar(sc,
                             ticks=[0, 24 * 15, 24 * 30, 24 * 45, 24 * 60],
                             orientation='horizontal',
                             shrink=0.5)
    color_bar.ax.set_xticklabels(
        ['Midnight', '18:00', 'Noon', '6:00', 'Midnight'])
    color_bar.ax.invert_xaxis()
    color_bar.ax.tick_params(labelsize=16)

    ax.set_yscale('log')  # logarithmic axes
    ax.set_xscale('log')

    plt.minorticks_off()

    pure_ticks = np.array([
        1e-3, 1, 10, 60 * 10, 2 * 3600, 1 * 24 * 3600, 7 * 24 * 3600
    ])  # where the tick marks will be placed, in units of seconds.
    labels = [
        '1 msec', '1 sec', '10 sec', '10 min', '2 hr', '1 day', '1 week'
    ]  # tick labels

    max_val = np.max([np.max(sep_array[:, 0]), np.max(sep_array[:, 1])])

    ticks = np.hstack((pure_ticks, max_val))

    min_val = np.min([np.min(sep_array[:, 0]), np.min(sep_array[:, 1])])

    plt.xticks(ticks, labels, fontsize=16)
    plt.yticks(ticks, labels, fontsize=16)

    plt.xlabel('Time Before Tweet', fontsize=18)
    plt.ylabel('Time After Tweet', fontsize=18)

    plt.xlim((min_val, max_val))
    plt.ylim((min_val, max_val))

    ax.set_aspect('equal')

    plt.tight_layout()

    plt.show()

    return None
コード例 #5
0
ファイル: _timemaps.py プロジェクト: zephyrthenoble/time-maps
def make_heated_time_map(
        sep_array,
        Nside,
        width,
        title=""):  # plot heated time map. Nothing is returned

    print("generating heated time map ...")

    # choose points within specified range. Example plot separations greater than 5 minutes:
    # 	indices = (sep_array[:,0]>5*60) & (sep_array[:,1]>5*60)
    indices = list(range(sep_array.shape[0]))  # all time separations

    x_pts = np.log(sep_array[indices, 0])
    y_pts = np.log(sep_array[indices, 1])

    min_val = np.min([np.min(x_pts), np.min(y_pts)])

    x_pts = x_pts - min_val
    y_pts = y_pts - min_val

    max_val = np.max([np.max(x_pts), np.max(y_pts)])

    x_pts *= (Nside - 1) / max_val
    y_pts *= (Nside - 1) / max_val

    img = np.zeros((Nside, Nside))

    for i in range(len(x_pts)):
        #  print(i)
        #  print((int)x_pts[i])
        #  print(y_pts[i])
        img[(int)(x_pts[i]), (int)(y_pts[i])] += 1

    img = ndi.gaussian_filter(img, width)  # apply Gaussian filter
    img = np.sqrt(
        img)  # taking the square root makes the lower values more visible
    img = np.transpose(
        img)  # needed so the orientation is the same as scatterplot

    plt.imshow(img, origin="lower")

    ## create custom tick marks. Calculate positions of tick marks on the transformed log scale of the image array
    plt.minorticks_off()

    ## change font, which can also now accept latex: http://matplotlib.org/users/usetex.html
    plt.rc("text", usetex=False)
    plt.rc("font", family="serif")

    my_max = np.max(
        [np.max(sep_array[indices, 0]),
         np.max(sep_array[indices, 1])])
    my_min = np.max(
        [np.min(sep_array[indices, 0]),
         np.min(sep_array[indices, 1])])

    pure_ticks = np.array(
        [1e-3, 1, 10, 60 * 10, 2 * 3600, 1 * 24 * 3600, 7 * 24 * 3600])
    # where the tick marks will be placed, in units of seconds. An additional value will be appended to the end for the max
    labels = [
        "1 ms",
        "1 s",
        "10 s",
        "10 m",
        "2 h",
        "1 d",
        "1 w",
    ]  # tick labels

    index_lower = np.min(np.nonzero(pure_ticks >= my_min))
    # index of minimum tick that is greater than or equal to the smallest time interval. This will be the first tick with a non-blank label

    index_upper = np.max(np.nonzero(pure_ticks <= my_max))
    # similar to index_lower, but for upperbound

    ticks = pure_ticks[index_lower:index_upper + 1]
    ticks = np.log(np.hstack(
        (my_min, ticks, my_max)
    ))  # append values to beginning and end in order to specify the limits
    ticks = ticks - min_val
    ticks *= (Nside - 1) / (max_val)

    labels = np.hstack(("", labels[index_lower:index_upper + 1],
                        ""))  # append blank labels to beginning and end
    plt.xticks(ticks, labels, fontsize=16)
    plt.yticks(ticks, labels, fontsize=16)
    plt.xlabel("Time Before Tweet", fontsize=18)
    plt.ylabel("Time After Tweet", fontsize=18)
    plt.title(title)
    plt.show()

    return None
コード例 #6
0
ファイル: _timemaps.py プロジェクト: zephyrthenoble/time-maps
def make_time_map(
        times, times_tot_mins, sep_array, Ncolors,
        title):  # plot standard, scatter-plot time map. Nothing is returned

    print("rendering normal time map ...")

    ## set up color list
    red = Color("red")
    blue = Color("blue")
    color_list = list(
        red.range_to(blue, Ncolors)
    )  # range of colors evenly speced on the spectrum between red and blue. Each element is a colour object
    color_list = [c.hex for c in color_list]  # give hex version

    fig = plt.figure()
    ax = fig.add_subplot(111)

    plt.rc("text", usetex=False)
    plt.rc("font", family="serif")

    colormap = plt.cm.get_cmap(
        "rainbow"
    )  # see color maps at http://matplotlib.org/users/colormaps.html

    order = np.argsort(times_tot_mins[1:-1])  # so that the red dots are on top
    # 	order=np.arange(1,len(times_tot_mins)-2) # dots are unsorted

    sc = ax.scatter(
        sep_array[:, 0][order],
        sep_array[:, 1][order],
        c=times_tot_mins[1:-1][order],
        vmin=0,
        vmax=24 * 60,
        s=25,
        cmap=colormap,
        marker="o",
        edgecolors="none",
    )
    # taken from http://stackoverflow.com/questions/6063876/matplotlib-colorbar-for-scatter

    color_bar = fig.colorbar(
        sc,
        ticks=[0, 24 * 15, 24 * 30, 24 * 45, 24 * 60],
        orientation="horizontal",
        shrink=0.5,
    )
    color_bar.ax.set_xticklabels(
        ["Midnight", "18:00", "Noon", "6:00", "Midnight"])
    color_bar.ax.invert_xaxis()
    color_bar.ax.tick_params(labelsize=16)

    ax.set_yscale("log")  # logarithmic axes
    ax.set_xscale("log")

    plt.minorticks_off()
    pure_ticks = np.array([
        1e-3, 1, 10, 60 * 10, 2 * 3600, 1 * 24 * 3600, 7 * 24 * 3600
    ])  # where the tick marks will be placed, in units of seconds.
    labels = [
        "1 ms",
        "1 s",
        "10 s",
        "10 m",
        "2 h",
        "1 d",
        "1 w",
    ]  # tick labels

    max_val = np.max([np.max(sep_array[:, 0]), np.max(sep_array[:, 1])])

    ticks = np.hstack((pure_ticks, max_val))

    min_val = np.min([np.min(sep_array[:, 0]), np.min(sep_array[:, 1])])

    plt.xticks(ticks, labels, fontsize=16)
    plt.yticks(ticks, labels, fontsize=16)

    plt.xlabel("Time Before Tweet", fontsize=18)
    plt.ylabel("Time After Tweet", fontsize=18)
    plt.title(title)

    plt.xlim((min_val, max_val))
    plt.ylim((min_val, max_val))

    ax.set_aspect("equal")
    plt.tight_layout()

    plt.show()