示例#1
0
def add_annotation_no_data(fig: go.Figure):
    fig.add_annotation(
        text="No data to display",
        xref="paper",
        yref="paper",
        showarrow=False,
        font={"size": 28},
    )
示例#2
0
    def __create_boxplot__(self,
                           data: pd.DataFrame,
                           title: str,
                           y_title: str,
                           show_data: bool = False,
                           show_sd: bool = False,
                           show_annotations: bool = True):
        fig = Figure()

        miny = data.min().min() - abs(0.15 * data.min().min())

        for k in data:
            box = Box(
                name=k,
                y=data[k],
                text=data[k].index.tolist(),
                line_color=self.target_colors[k],
                marker_color=self.target_colors[k],
                boxpoints='outliers',
                marker=dict(color='rgb(8,81,156)',
                            outliercolor='rgba(219, 64, 82, 0.6)',
                            line=dict(outliercolor='rgba(219, 64, 82, 0.6)',
                                      outlierwidth=2)),
            )
            fig.add_trace(box)
            if show_annotations:
                stdev = np.std(data[k])
                fig.add_annotation(x=k,
                                   y=miny,
                                   text=u'\u03C3' + f' = {stdev:.4f}',
                                   showarrow=False)

        if show_data:
            fig.update_traces(boxpoints='all', jitter=0, pointpos=-0.5)

        if show_sd:
            fig.update_traces(boxmean='sd')

        fig.update_layout(
            title=dict(text=title,
                       x=0.5,
                       y=0.98,
                       font_size=28,
                       xanchor='center',
                       yanchor='top'),
            paper_bgcolor='white',
            plot_bgcolor='white',
            xaxis=dict(showgrid=False, zeroline=False, showticklabels=True),
            yaxis=dict(showgrid=True,
                       zeroline=True,
                       showticklabels=True,
                       gridcolor='lightgray'),
            yaxis_title=dict(text=y_title, font=dict(size=24)),
            autosize=True,
            # width=2048,
            showlegend=False)

        return fig
示例#3
0
def add_timed_annotation(fig: plotly_go.Figure,
                         value: float,
                         timestamp: datetime,
                         yaxis: str,
                         row: int,
                         col: int,
                         value_fmt: str = '.2f',
                         postfix: str = '',
                         hue: float = 210,
                         opacity: float = 1.0,
                         **kwargs) -> None:
    color: str = f'hsla({hue:.0f}, 100%, 67%, {0.5 * opacity:.2f})'
    border_color: str = f'hsla({hue:.0f}, 100%, 10%, {0.75 * opacity:.2f})'
    font_color: str = f'hsla({hue:.0f}, 67%, 90%, {0.9 * opacity:.2f})'
    font_size: float = 10
    text: str = f'{value:{value_fmt}}{postfix}'
    fig.add_annotation(x=timestamp,
                       y=value,
                       yref=yaxis,
                       text=text,
                       font=dict(size=font_size, color=font_color),
                       showarrow=True,
                       arrowhead=2,
                       arrowsize=1,
                       arrowwidth=2,
                       ax=11,
                       ay=0,
                       xanchor='left',
                       yanchor='middle',
                       standoff=1,
                       arrowcolor=color,
                       bgcolor=color,
                       bordercolor=border_color,
                       opacity=opacity,
                       row=row,
                       col=col,
                       **kwargs)
def main(is_oblasts_filled: bool, is_roads_visible: bool):
    """
    Головна функція програми, яка виконує малювання (рендеринг) карти. Вона
    почергово створює усі необхідні рівні в порядку накладання - області,
    міста, річки й дороги. Після цього кожен рівень розміщує на загальному
    "полотні" дані з файлів й текстові анотації (для міст). В кінці полотно
    масштабується за віссю Y, аби результуюча картинка не була розтягнена.
    Варто зазначити, що бібліотека для малювання дозволяє інтерактивно
    взаємодіяти з отриманою картою, але в дуже мінімальних межах -
    переважно через те, що карта відмальовує надто велику кількість
    багатокутників і точок. Дана бібліотека не призначена для малювання ГІС,
    для цього куди краще підійдуть спеціалізовані графічні двигуни й дані в
    більш специфічному форматі - наприклад, shapefile або KML, але це
    виходить за межі даної лабораторної.
    """
    layers = [
        Layer(
            'oblasts',
            is_filled=is_oblasts_filled,
            outer_fill_color='#ebf2e7',
            outer_line_color='#b46198',
            outer_line_width=2
        ),
        Layer(
            'cities',
            is_named=True,
            outer_fill_color='#a1a0a0',
            outer_line_color='#656464',
            outer_line_width=1,
            inner_fill_color='#ebf2e7',
            inner_line_color='#ebf2e7'
        ),
        Layer(
            'rivers',
            outer_fill_color='#9fcee5',
            outer_line_color='#2a5eea',
            outer_line_width=1,
            inner_fill_color='#ebf2e7',
            inner_line_color='#2a5eea',
            inner_line_width=1
        ),
        Layer(
            'roads',
            is_visible=is_roads_visible,
            outer_line_color='#ffb732',
            outer_line_width=2
        )
    ]
    figure = Figure()
    for layer in layers:
        scatters, annotations = layer.render2d()
        figure.add_traces(scatters)
        for annotation in annotations:
            figure.add_annotation(**annotation)
    figure.update_layout(plot_bgcolor='rgba(0,0,0,0)', showlegend=False)
    figure.update_xaxes(
        showline=True,
        linewidth=2,
        linecolor='#8b8b8b',
        mirror=True
    )
    figure.update_yaxes(
        scaleanchor='x',
        scaleratio=1.5,
        showline=True,
        linewidth=2,
        linecolor='#8b8b8b',
        mirror=True
    )
    figure.show()