Esempio n. 1
0
def layout_padding(plots):
    """
    Temporary workaround to allow empty plots in a
    row of a bokeh GridPlot type. Should be removed
    when https://github.com/bokeh/bokeh/issues/2891
    is resolved.
    """
    widths, heights = defaultdict(int), defaultdict(int)
    for r, row in enumerate(plots):
        for c, p in enumerate(row):
            if p is not None:
                width = p.plot_width if isinstance(p, Plot) else p.width
                height = p.plot_height if isinstance(p, Plot) else p.height
                widths[c] = max(widths[c], width)
                heights[r] = max(heights[r], height)

    expanded_plots = []
    for r, row in enumerate(plots):
        expanded_plots.append([])
        for c, p in enumerate(row):
            if p is None:
                p = Figure(plot_width=widths[c],
                           plot_height=heights[r])
                p.text(x=0, y=0, text=[' '])
                p.xaxis.visible = False
                p.yaxis.visible = False
                p.outline_line_color = None
                p.xgrid.grid_line_color = None
                p.ygrid.grid_line_color = None
            expanded_plots[r].append(p)
    return expanded_plots
Esempio n. 2
0
    ("R.A. (deg)", "@ra{1.111}"),
    ("Dec. (deg)", "@dec{1.111}"),
    ("Claimed type", "@claimedtype")
]
hover = HoverTool(tooltips=tt)

p1 = Figure(title='Supernova Positions', x_axis_label='Right Ascension (deg)',
            # responsive = True,
            y_axis_label='Declination (deg)', tools=tools, plot_width=980,
            plot_height=720,
            x_range=(-1.05 * (2.0**1.5), 1.3 * 2.0**1.5),
            y_range=(-2.0 * sqrt(2.0), 1.2 * sqrt(2.0)),
            min_border_bottom=0,
            min_border_left=0, min_border=0)
p1.axis.visible = None
p1.outline_line_color = None
p1.xgrid.grid_line_color = None
p1.ygrid.grid_line_color = None
p1.title.text_font_size = '20pt'

raxs = []
rays = []
for rg in ragrid:
    raxs.append([2.0**1.5 * cos(x) * sin(rg / 2.0) /
                 sqrt(1.0 + cos(x) * cos(rg / 2.0)) for x in decrange])
    rays.append([sqrt(2.0) * sin(x) / sqrt(1.0 + cos(x) * cos(rg / 2.0))
                 for x in decrange])

decxs = []
decys = []
for dg in decgrid:
freq_bars = plot.quad(top='hist', bottom=0, left='left_edge', right='right_edge',
                      source=source, fill_color=YlOrBr3[0], line_color='#000000')

plot.xaxis.axis_label = "Total Score"
plot.xaxis.axis_line_color = None
plot.xaxis.minor_tick_line_color = None

plot.yaxis.axis_label = "Frequency"
plot.yaxis.axis_line_color = None
plot.yaxis.major_tick_line_color = None
plot.yaxis.minor_tick_line_color = None

plot.xgrid.grid_line_color = None
plot.ygrid.grid_line_color = None

plot.outline_line_color = None

plot.logo = None

bar_hover = HoverTool(renderers=[freq_bars], tooltips=[("Range", '@left_edge to @right_edge'),
                      ("Frequency", '@hist'), ("Total # Samples", '@samples')])
plot.add_tools(bar_hover)

# Dropdown and interactive UI elements
selectable_years = ["All Years"] + list(map(str, compdata['Year'].unique()))
selectable_events = ["All Events"] + [event.replace(' Score', '') for event in compdata.columns.values.tolist()[5:13]]

select_year = Select(title="Year", value="All Years", options=selectable_years)
select_event = Select(title="Event", value="All Events", options=selectable_events)

              fill_alpha=0,
              size=20)
plot.square(x='x', y='y', source=col4.square, color='black', size=20)
# Plot buckling lenghts
plot.line(x='x', y='y', source=col1.sk, color='#A2AD00', line_width=2)
plot.line(x='x', y='y', source=col2.sk, color='#A2AD00', line_width=2)
plot.line(x='x', y='y', source=col3.sk, color='#A2AD00', line_width=2)
plot.line(x='x', y='y', source=col4.sk, color='#A2AD00', line_width=2)

#Main plot properties:
plot.axis.visible = False
plot.grid.visible = False
plot.toolbar.logo = None
plot.outline_line_width = 1
plot.outline_line_alpha = 0.5
plot.outline_line_color = "Black"
plot.title.text_font_size = "18pt"
plot.width = 900

#Labels section:
# F and column name
labels1 = LatexLabelSet(x='x',
                        y='y',
                        text='name',
                        level='glyph',
                        x_offset=-20,
                        y_offset=0,
                        source=col1.labels,
                        render_mode='canvas')
labels2 = LatexLabelSet(x='x',
                        y='y',
Esempio n. 5
0
    ("R.A. (deg)", "@ra{1.111}"),
    ("Dec. (deg)", "@dec{1.111}")
]
if args.catalog == 'hvs':
    tt.append(("R.A. proper motion (mas/yr)", "@propermotionra"))
    tt.append(("Dec. proper motion (mas/yr)", "@propermotiondec"))
    tt.append(("Radial velocity (km/s)", "@velocity"))
    tt.append(("Galactocentric velocity (km/s)", "@galactocentricvelocity"))
    tt.append(("Bound probability", "@boundprobability"))
p1 = Figure(title=moduletitle + ' Positions',
            # responsive = True,
            tools=tools, plot_width=990,
            x_range=(-1.05 * (2.0**1.5), 1.05 * 2.0**1.5),
            y_range=(-1.4 * sqrt(2.0), 1.0 * sqrt(2.0)))
p1.axis.visible = False
p1.outline_line_color = None
p1.xgrid.grid_line_color = None
p1.ygrid.grid_line_color = None
p1.title.text_font_size = '20pt'
p1.title.align = 'center'

raxs = []
rays = []
for rg in ragrid:
    raxs.append([2.0**1.5 * cos(x) * sin(rg / 2.0) /
                 sqrt(1.0 + cos(x) * cos(rg / 2.0)) for x in decrange])
    rays.append([sqrt(2.0) * sin(x) / sqrt(1.0 + cos(x) * cos(rg / 2.0))
                 for x in decrange])

p1.multi_line(raxs, rays, color='#bbbbbb')
Esempio n. 6
0
    def plot_amp(self,
                 dz,
                 refexp,
                 name="",
                 font_size="1.2vw",
                 description="",
                 wrg=[]):
        ''' Initializing AMP plot
        '''
        ztext, cbarformat = self.set_amp(dz)
        dx = [0, 1, 0, 1]
        dy = [1, 1, 0, 0]

        cmap_tooltip = """
            <div>

                <div>
                    <span style="font-size: 1vw; font-weight: bold; color: #303030;">AMP: </span>
                    <span style="font-size: 1vw; color: #515151;">@amp_number</span>
                </div>
                <div>
                    <span style="font-size: 1vw; font-weight: bold; color: #303030;">counts: </span>
                    <span style="font-size: 1vw; color: #515151">@ztext</span>
                </div>
                <div>
                    <span style="font-size: 1vw; font-weight: bold; color: #303030;">Reference: </span>
                    <span style="font-size: 1vw; color: #515151;">@ref</span>
                </div>
            </div>
        """.replace("counts:",
                    name.replace("_AMP", "") + ":")
        hover = HoverTool(tooltips=cmap_tooltip)

        p = Figure(title=name,
                   tools=[hover],
                   x_range=list([-0.5, 1.5]),
                   y_range=list([-0.5, 1.5]),
                   plot_width=450,
                   plot_height=400)

        p.xaxis.axis_label_text_font_size = font_size
        p.legend.label_text_font_size = font_size
        p.title.text_font_size = font_size

        p.xaxis.axis_label = description

        cmap = get_palette("RdBu_r")
        mapper = LinearColorMapper(palette=cmap,
                                   low=wrg[0],
                                   high=wrg[1],
                                   nan_color="darkgrey")

        formatter = PrintfTickFormatter(format=cbarformat)
        color_bar = ColorBar(color_mapper=mapper,
                             major_label_text_align='left',
                             major_label_text_font_size='10pt',
                             label_standoff=2,
                             location=(0, 0),
                             formatter=formatter,
                             title="(Val-Ref)",
                             title_standoff=15,
                             title_text_baseline="alphabetic")
        p.add_layout(color_bar, 'right')

        p.grid.grid_line_color = None
        p.outline_line_color = None
        p.axis.clear
        p.axis.minor_tick_line_color = None

        p.axis.major_label_text_font_size = '0pt'
        p.yaxis.major_label_text_font_size = '0pt'
        p.xaxis.major_tick_line_color = None
        p.xaxis.minor_tick_line_color = None
        p.yaxis.major_tick_line_color = None
        p.yaxis.minor_tick_line_color = None
        p.yaxis.visible = False
        p.xaxis.visible = True

        zvalid = [x if x > -999 else np.nan for x in dz]
        source = ColumnDataSource(data=dict(
            x=dx,
            y=dy,
            z=dz,
            zvalid=zvalid,
            ref=["{:.2f}".format(x) for x in refexp],
            zdiff=np.array(zvalid) - np.array(refexp),
            y_offset1=[i + 0.15 for i in dy],
            y_offset2=[i - 0.10 for i in dy],
            amp=['AMP %s' % i for i in range(1, 5)],
            amp_number=['%s' % i for i in range(1, 5)],
            ztext=ztext,
        ))

        text_props = {
            "source": source,
            "angle": 0,
            "color": "black",
            "text_color": "black",
            "text_align": "center",
            "text_baseline": "middle"
        }

        p.rect("x",
               "y",
               .98,
               .98,
               0,
               source=source,
               fill_color={
                   'field': 'zdiff',
                   'transform': mapper
               },
               fill_alpha=0.9)

        p.text(x="x",
               y="y_offset1",
               text="amp",
               text_font_size="2vw",
               **text_props)
        p.text(x="x",
               y="y_offset2",
               text="ztext",
               text_font_style="bold",
               text_font_size="2.5vw",
               **text_props)

        return p
Esempio n. 7
0
                      fill_color='OliveDrab',
                      line_color='#000000')

plot.xaxis.axis_label = "Weight [kg]"
plot.xaxis.axis_line_color = None
plot.xaxis.minor_tick_line_color = None

plot.yaxis.axis_label = "Frequency"
plot.yaxis.axis_line_color = None
plot.yaxis.major_tick_line_color = None
plot.yaxis.minor_tick_line_color = None

plot.xgrid.grid_line_color = None
plot.ygrid.grid_line_color = None

plot.outline_line_color = None

plot.logo = None

bar_hover = HoverTool(renderers=[freq_bars],
                      tooltips=[("Range", '@left_edge to @right_edge'),
                                ("Frequency", '@hist'),
                                ("Total # Samples", '@samples')])
plot.add_tools(bar_hover)

# Dropdown and interactive UI elements
selectable_years = compdata.loc[compdata['Year'] >= 2013]
selectable_years = ["All Years"] + list(
    map(str, selectable_years['Year'].unique()))

select_year = Select(title="Year",
    def _segment_plot(self, source):
        """Plot showing the mirror segments.

        The plot shows the 91 segment positions with their position number. The colour of the segments indicates how
        long ago they have been recoated.

        Params:
        -------
        source: pandas.DataFrame
            Data source.

        Returns:
        --------
        bokeh.plotting.Figure
            Plot showing the mirror segments.
        """

        def segment_color(date):
            """Fill colour of a mirror segment."""
            days = (datetime.datetime.now().date() - date).days
            days = min(days, self.RECOATING_PERIOD)
            days = max(days, 0)

            def hex_value(v):
                """Convert integer into a hexadecimal string suitable for specifying an RGB value in a css rule."""
                s = format(int(round(255 * v)), 'x')
                if len(s) < 2:
                    s = '0' + s
                return s

            # The colour ranges from dark green for recently recoated segments to white for segments which need to be
            # recoated.
            h = 99
            s = 100
            l = 33 + 67 * days / self.RECOATING_PERIOD
            rgb = colorsys.hls_to_rgb(h / 360, l / 100, s / 100)

            return '#{r}{g}{b}'.format(r=hex_value(rgb[0]),
                                       g=hex_value(rgb[1]),
                                       b=hex_value(rgb[2]))

        plot = Figure(tools='tap', toolbar_location=None)
        colors = [segment_color(d) for d in source.data['ReplacementDate']]
        plot.patches(xs='SegmentPositionCornerXs',
                     ys='SegmentPositionCornerYs',
                     source=source,
                     color=colors,
                     line_color='#dddddd')
        plot.text(x='SegmentPositionX',
                  y='SegmentPositionY',
                  text='SegmentPosition',
                  source=source,
                  text_color='black',
                  text_align='center',
                  text_baseline='middle')

        plot.grid.grid_line_color = None
        plot.axis.visible = False

        plot.min_border_top = 20
        plot.min_border_bottom = 30

        plot.outline_line_color = None

        return plot