def plot_orbit(z0=0.5+0.5*1j, c=0+0*1j):
    sc_x = bqplot.LinearScale(min=-1.2, max=1.2)
    sc_y = bqplot.LinearScale(min=-1.2, max=1.2)

    c_point = bqplot.Scatter(x=[c.real], y=[c.imag], scales={'x': sc_x, 'y': sc_y}, colors=['red'],
                   enable_move=True, default_size=200)
    c_point.update_on_move = True

    z_point = bqplot.Scatter(x=[z0.real], y=[z0.imag], scales={'x': sc_x, 'y': sc_y}, colors=['green'],
                   enable_move=True, default_size=200)
    z_point.update_on_move = True

    c_label = bqplot.Label(x=[c.real+.05], y=[c.imag+.05], scales={'x': sc_x, 'y': sc_y}, colors=['red'],
                           text=['c'],
                           default_size=26, font_weight='bolder')

    z_label = bqplot.Label(x=[z0.real+.05], y=[z0.imag+.05], scales={'x': sc_x, 'y': sc_y}, colors=['green'],
                           text=['z0'],
                           default_size=26, font_weight='bolder')
    
    scatt = bqplot.Scatter(x=[], y=[], scales={'x': sc_x, 'y': sc_y}, colors=['black'], default_size=20)

    theta = np.linspace(0, 2.*np.pi, 1000)
    x = np.cos(theta)
    y = np.sin(theta)
    circle = bqplot.Lines(x=x, y=y, scales={'x': sc_x, 'y': sc_y}, colors=['black'])
    lin = bqplot.Lines(x=[], y=[], scales={'x': sc_x, 'y': sc_y}, colors=['black'], stroke_width=1)

    def update_line(change=None):
        out = orbit(z_point.x + 1j*z_point.y, c_point.x + 1j*c_point.y)
        c_label.x = c_point.x + 0.05
        c_label.y = c_point.y + 0.05
        z_label.x = z_point.x + 0.05
        z_label.y = z_point.y + 0.05
        lin.x = out.real
        lin.y = out.imag
        scatt.x = out.real.flatten()
        scatt.y = out.imag.flatten()

    update_line()
    # update line on change of x or y of scatter
    c_point.observe(update_line, names=['x'])
    c_point.observe(update_line, names=['y'])
    z_point.observe(update_line, names=['x'])
    z_point.observe(update_line, names=['y'])
    ax_x = bqplot.Axis(scale=sc_x, offset=dict(value=0.5), grid_lines='none')
    ax_y = bqplot.Axis(scale=sc_y, orientation='vertical', offset=dict(value=0.5), grid_lines='none')

    fig = bqplot.Figure(marks=[scatt, lin, circle, c_point, z_point, c_label, z_label], axes=[ax_x, ax_y],
                 min_aspect_ratio=1, max_aspect_ratio=1)
    fig.layout.height = '800px'
    return fig
Пример #2
0
def test_binary_serialize_text():
    # string do not get serialized in binary (since numpy uses utf32, and js/browsers do not support that)
    text = np.array(['aap', 'noot', 'mies'])
    label = bqplot.Label(text=text)

    state = label.get_state()
    assert state['text'] == ['aap', 'noot', 'mies']

    # currently a roundtrip does not converse the datetime64 type
    label2 = bqplot.Label()
    label2.set_state(state)

    assert label2.text.tolist() == label.text.tolist()
Пример #3
0
hydrogen_line1 = bq.Lines(x=H_spectra_array, y=height1, scales={'x': x_sc, 'y': y_sc}, 
                          colors=['black'] ,opacities=[.3,.8,.3,.3,.8,.3,.3,.8,.3,.3,.8,.3])
# Large star (blue) for Figure 2
hydrogen_line2 = bq.Lines(x=H_spectra_array, y=height2, scales={'x': x_sc, 'y': y_sc}, 
                          colors=['black'] ,opacities=[.3,.8,.3,.3,.8,.3,.3,.8,.3,.3,.8,.3])
# Small star (red) for Figure 2
hydrogen_line3 = bq.Lines(x=H_spectra_array, y=height2, scales={'x': x_sc, 'y': y_sc}, 
                          colors=['#303030'] ,opacities=[.3,.8,.3,.3,.8,.3,.3,.8,.3,.3,.8,.3])

# This is the line command that draws all the lines
fig1_wide_line = bq.Lines(x = fin_x_array, y = fin_y_array, scales={'x': x_sc_fig1, 'y': y_sc_fig1}, colors=colors_list)
wide_line = bq.Lines(x = fin_x_array, y = fin_y_array, scales={'x': x_sc, 'y': y_sc}, colors=colors_list)

# Labels the lab and source spectra on the figure
fig1_Lab_label = bq.Label(x=[580,580], y=[0.1,0.8], scales={'x': x_sc_fig1, 'y': y_sc_fig1},
                   text=['Laboratory Spectrum','Source Spectrum'], default_size=15, font_weight='bolder',
                   colors=['black'], update_on_move=False, align='middle')
Lab_label = bq.Label(x=[580,580], y=[0.1,0.8], scales={'x': x_sc, 'y': y_sc},
                   text=['Laboratory Spectrum','Source Spectrum'], default_size=15, font_weight='bolder',
                   colors=['black'], update_on_move=False, align='middle')


##
## Setup Figure 1
##

# Slider to adjust velocity (away or towards Earth) of the star in question
fig1_vel_slider = widgets.IntSlider(
    value=0,
    min=-5e6,
    max=5e6,
#fig_margin={'top':20, 'bottom':30, 'left':80, 'right':20})

#fig_bar = bqp.Figure(marks=[bar,bar_labels], axes=[ax_x, ax_y], padding_x=0.025, padding_y=0.025,
#                     layout=Layout(width='600px'), legend_location='top',
#                     fig_margin={'top':20, 'bottom':30, 'left':110, 'right':20})

ax_x = bqp.Axis(scale=x_ord, orientation="vertical", color='Black')
ax_y = bqp.Axis(scale=y_sc, tick_format='0.2f', color='White')

labels_initial = bqp.Label(
    y=[],
    x=[],
    scales={
        'y': x_ord,
        'x': y_sc
    },  #contain value of weights but only for the labels not the bars.
    x_offset=2,
    y_offset=-17,
    text=[],
    colors=['#4fa110'],
    default_size=14,
    update_on_move=True)

labels_opt = bqp.Label(y=[],
                       x=[],
                       scales={
                           'y': x_ord,
                           'x': y_sc
                       },
                       x_offset=2,
                       y_offset=0,