Exemple #1
0
def bokeh_plot(u, t, legends, U, omega, t_range, filename):
	"""
	Строится график зависимости приближенного решения от t с 
	использованием библиотеки Bokeh.
	u и t - списки (несколько экспериментов могут сравниваться).
	легенды содержат строки для различных пар u,t.
    """
	if not isinstance(u, (list,tuple)):
		u = [u]  
	if not isinstance(t, (list,tuple)):
		t = [t]  
	if not isinstance(legends, (list,tuple)):
		legends = [legends] 

	import bokeh.plotting as plt
	plt.output_file(filename, mode='cdn', title='Comparison')
	# Предполагаем, что все массивы t имеют одинаковые размеры
	t_fine = np.linspace(0, t[0][-1], 1001)  # мелкая сетка для точного решения
	tools = 'pan,wheel_zoom,box_zoom,reset,'\
	        'save,box_select,lasso_select'
	u_range = [-1.2*U, 1.2*U]
	font_size = '8pt'
	p = []  # список графических объектов
	# Создаем первую фигуру
	p_ = plt.figure(
		width=300, plot_height=250, title=legends[0],
		x_axis_label='t', y_axis_label='u',
		x_range=t_range, y_range=u_range, tools=tools,
		title_text_font_size=font_size)
	p_.xaxis.axis_label_text_font_size=font_size
	p_.yaxis.axis_label_text_font_size=font_size
	p_.line(t[0], u[0], line_color='blue')
	# Добавляем точное решение
	u_e = u_exact(t_fine, U, omega)
	p_.line(t_fine, u_e, line_color='red', line_dash='4 4')
	p.append(p_)
	# Создаем оставшиеся фигуры и добавляем их оси к осям первой фигуры
	for i in range(1, len(t)):
		p_ = plt.figure(
			width=300, plot_height=250, title=legends[i],
			x_axis_label='t', y_axis_label='u',
			x_range=p[0].x_range, y_range=p[0].y_range, tools=tools,
			title_text_font_size=font_size)
		p_.xaxis.axis_label_text_font_size = font_size
		p_.yaxis.axis_label_text_font_size = font_size
		p_.line(t[i], u[i], line_color='blue')
		p_.line(t_fine, u_e, line_color='red', line_dash='4 4')
		p.append(p_)
		
	# Располагаем все графики на сетке с 3 графиками в строке
	grid = [[]]
	for i, p_ in enumerate(p):
		grid[-1].append(p_)
		if (i+1) % 3 == 0:
			# Новая строка
			grid.append([])
	plot = plt.gridplot(grid, toolbar_location='left')
	plt.save(plot)
	plt.show(plot)
Exemple #2
0
def bokeh_plot(u, t, legends, I, w, t_range, filename):
    """
    Make plots for u vs t using the Bokeh library.
    u and t are lists (several experiments can be compared).
    legens contain legend strings for the various u,t pairs.
    """
    if not isinstance(u, (list,tuple)):
        u = [u]  # wrap in list
    if not isinstance(t, (list,tuple)):
        t = [t]  # wrap in list
    if not isinstance(legends, (list,tuple)):
        legends = [legends]  # wrap in list

    import bokeh.plotting as plt
    plt.output_file(filename, mode='cdn', title='Comparison')
    # Assume that all t arrays have the same range
    t_fine = np.linspace(0, t[0][-1], 1001)  # fine mesh for u_e
    tools = 'pan,wheel_zoom,box_zoom,reset,'\
            'save,box_select,lasso_select'
    u_range = [-1.2*I, 1.2*I]
    font_size = '8pt'
    p = []  # list of plot objects
    # Make the first figure
    p_ = plt.figure(
        width=300, plot_height=250, title=legends[0],
        x_axis_label='t', y_axis_label='u',
        x_range=t_range, y_range=u_range, tools=tools,
        title_text_font_size=font_size)
    p_.xaxis.axis_label_text_font_size=font_size
    p_.yaxis.axis_label_text_font_size=font_size
    p_.line(t[0], u[0], line_color='blue')
    # Add exact solution
    u_e = u_exact(t_fine, I, w)
    p_.line(t_fine, u_e, line_color='red', line_dash='4 4')
    p.append(p_)
    # Make the rest of the figures and attach their axes to
    # the first figure's axes
    for i in range(1, len(t)):
        p_ = plt.figure(
            width=300, plot_height=250, title=legends[i],
            x_axis_label='t', y_axis_label='u',
            x_range=p[0].x_range, y_range=p[0].y_range, tools=tools,
            title_text_font_size=font_size)
        p_.xaxis.axis_label_text_font_size = font_size
        p_.yaxis.axis_label_text_font_size = font_size
        p_.line(t[i], u[i], line_color='blue')
        p_.line(t_fine, u_e, line_color='red', line_dash='4 4')
        p.append(p_)

    # Arrange all plots in a grid with 3 plots per row
    grid = [[]]
    for i, p_ in enumerate(p):
        grid[-1].append(p_)
        if (i+1) % 3 == 0:
            # New row
            grid.append([])
    plot = plt.gridplot(grid, toolbar_location='left')
    plt.save(plot)
    plt.show(plot)
Exemple #3
0
def bokeh_plot(u, t, legends, I, w, t_range, filename):
    """
    Make plots for u vs t using the Bokeh library.
    u and t are lists (several experiments can be compared).
    legens contain legend strings for the various u,t pairs.
    """
    if not isinstance(u, (list, tuple)):
        u = [u]  # wrap in list
    if not isinstance(t, (list, tuple)):
        t = [t]  # wrap in list
    if not isinstance(legends, (list, tuple)):
        legends = [legends]  # wrap in list

    import bokeh.plotting as plt
    plt.output_file(filename, mode='cdn', title='Comparison')
    # Assume that all t arrays have the same range
    t_fine = np.linspace(0, t[0][-1], 1001)  # fine mesh for u_e
    tools = 'pan,wheel_zoom,box_zoom,reset,'\
            'save,box_select,lasso_select'
    u_range = [-1.2 * I, 1.2 * I]
    font_size = '8pt'
    p = []  # list of plot objects
    # Make the first figure
    p_ = plt.figure(width=300,
                    plot_height=250,
                    title=legends[0],
                    x_axis_label='t',
                    y_axis_label='u',
                    x_range=t_range,
                    y_range=u_range,
                    tools=tools,
                    title_text_font_size=font_size)
    p_.xaxis.axis_label_text_font_size = font_size
    p_.yaxis.axis_label_text_font_size = font_size
    p_.line(t[0], u[0], line_color='blue')
    # Add exact solution
    u_e = u_exact(t_fine, I, w)
    p_.line(t_fine, u_e, line_color='red', line_dash='4 4')
    p.append(p_)
    # Make the rest of the figures and attach their axes to
    # the first figure's axes
    for i in range(1, len(t)):
        p_ = plt.figure(width=300,
                        plot_height=250,
                        title=legends[i],
                        x_axis_label='t',
                        y_axis_label='u',
                        x_range=p[0].x_range,
                        y_range=p[0].y_range,
                        tools=tools,
                        title_text_font_size=font_size)
        p_.xaxis.axis_label_text_font_size = font_size
        p_.yaxis.axis_label_text_font_size = font_size
        p_.line(t[i], u[i], line_color='blue')
        p_.line(t_fine, u_e, line_color='red', line_dash='4 4')
        p.append(p_)

    # Arrange all plots in a grid with 3 plots per row
    grid = [[]]
    for i, p_ in enumerate(p):
        grid[-1].append(p_)
        if (i + 1) % 3 == 0:
            # New row
            grid.append([])
    plot = plt.gridplot(grid, toolbar_location='left')
    plt.save(plot)
    plt.show(plot)