axis_line_style='{draw=none}',
    legend_cell_align='{left}',
    legend_style='{font=\\footnotesize, draw=none, fill=none}',
    ylabel_style='{yshift=-3.5mm}',
    bar_width='4mm',
    ybar='0mm',
    xticklabel_style='{font=\\footnotesize}',
    xtick_style='{draw=none}',
    ytick_style='{draw=none}',
)
plot.axis.options += (
    'nodes near coords',
    'every node near coord/.append style={font=\\scriptsize}',
)

plot.add_plot(x, y1, 'fill', draw='none', legend='Modèle 1')
plot.add_plot(x, y2, 'fill', draw='none', legend='Modèle 2')

plot.legend_position = 'north west'

plot.y_min = 0
plot.y_max = 79
plot.x_min = 0.5
plot.x_ticks = x
plot.x_ticks_labels = labels

plot.x_label = 'Datasets'
plot.y_label = "Précision (\%)"

doc = Document('bar_chart_example',
               filepath='./examples/',
Exemple #2
0
    def plot_all_to_latex(self, sec, mean_metrics, std_metrics, caption,
                          file_path, file_name):
        plot = sec.new(
            Plot(plot_name=file_name,
                 plot_path=file_path,
                 position='th!',
                 width=r'.27\textwidth',
                 height=r'.25\textwidth',
                 label=file_name,
                 name='plot0',
                 xshift=r'-.115\textwidth'))
        plot.caption = caption

        kwargs_per_plot = {
            1: {
                'as_float_env': False,
                'at': '(plot0.south east)',
                'anchor': 'south west',
                'xshift': r'-.04\textwidth',
                'name': 'plot1'
            },
            2: {
                'as_float_env': False,
                'at': '(plot1.south east)',
                'anchor': 'south west',
                'xshift': r'0.035\textwidth',
                'name': 'plot2'
            },
            3: {
                'as_float_env': False,
                'at': '(plot2.south east)',
                'anchor': 'south west',
                'xshift': r'.11\textwidth',
                'name': 'plot3'
            }
        }
        titles = {
            'de': 'English-Deutsch',
            'it': 'English-Italian',
            'fi': 'English-Finnish',
            'es': 'English-Spanish'
        }

        for i, language in enumerate(sorted(mean_metrics['accuracies'])):
            if i == 0:
                current_plot = plot
            else:
                current_plot = Plot(plot_name=file_name,
                                    plot_path=file_path,
                                    width=r'.27\textwidth',
                                    height=r'.25\textwidth',
                                    **kwargs_per_plot[i])
                current_plot.tikzpicture.head = ''
                current_plot.tikzpicture.tail = ''

            x, y, std = np.array(
                list(mean_metrics['accuracies'][language].keys())).astype(
                    int), np.array(
                        list(mean_metrics['accuracies']
                             [language].values())).astype(float), np.array(
                                 list(std_metrics['accuracies']
                                      [language].values())).astype(float)
            sorting = x.argsort()
            x, y, std = x[sorting], y[sorting], std[sorting]

            current_plot.add_plot(x,
                                  y,
                                  'blue',
                                  'ylabel near ticks',
                                  mark='*',
                                  line_width='1.2pt',
                                  mark_size='.9pt')
            current_plot.add_plot(x,
                                  y + 1.96 * std,
                                  name_path='upper',
                                  draw='none')
            current_plot.add_plot(x,
                                  y - 1.96 * std,
                                  name_path='lower',
                                  draw='none')
            current_plot.axis.append(
                '\\addplot[fill=blue!10] fill between[of=upper and lower];')
            current_plot.axis.kwoptions[
                'y tick label style'] = '{/pgf/number format/fixed zerofill, /pgf/number format/precision=1}'

            current_plot.x_min = np.floor(x.min())
            current_plot.x_max = np.ceil(x.max())
            y_max, y_min = (y + 1.96 * std).max(), (y - 1.96 * std).min()
            delta = y.max() - y.min()
            current_plot.y_min = y_min - delta / 2
            current_plot.y_max = y_max + delta / 2

            current_plot.title = titles[language]
            current_plot.plot_name += '_en_{}'.format(language)

            if i > 0:
                plot.tikzpicture += current_plot
y2 = f(x, .8, 2)
y3 = f(x, .65, 2.5)
y4 = f(x, .55, 3)
y5 = f(x, .5, 3.5)

plot = Plot(
    plot_path='./examples/',
    plot_name='lineplot_example',
    as_float_env=False,
    grid_style=('gray!35', 'ultra thin'),
    width='7cm',
    height='6cm',
    ylabel_style='{yshift=-3.5mm}',
)

plot.add_plot(x * 1000, y1, label='\\scriptsize$p=10$')
plot.add_plot(x * 1000, y2, label='\\scriptsize$p=30$')
plot.add_plot(x * 1000, y3, label='\\scriptsize$p=50$')
plot.add_plot(x * 1000, y4, label='\\scriptsize$p=75$')
plot.add_plot(x * 1000, y5, label='\\scriptsize$p=100$')

plot.y_min = 0
plot.y_max = 6.2
plot.x_min = 0
plot.x_max = 900

plot.x_label = 'Abscisse (unité)'
plot.y_label = 'Ordonnée (unité)'

doc = Document('lineplot_example',
               filepath='./examples/',
plot = Plot(
    plot_path='./examples/',
    plot_name='scatterplot',
    as_float_env=False,
    marks=True,
    lines=False,
    grid_style=('gray!35', 'ultra thin'),
    width='7cm',
    height='6cm',
    legend_cell_align='{left}',
    legend_style='{font=\\footnotesize,draw=gray!50}',
    ylabel_style='{yshift=-3.5mm}',
)

plot.add_plot(x1, y1+2, legend='Cercle indigo', fill_opacity=.5)
plot.add_plot(x2, y2+2, mark='triangle*', mark_size='2.5pt', legend='Triangle orange', fill_opacity=.5)

plot.legend_position = 'south east'

plot.y_min = 0
plot.x_min = 0
plot.x_ticks = (0,2,4,6,8)
plot.y_ticks = np.linspace(0,10,5)

plot.x_label = 'Abscisse (unité)'
plot.y_label = 'Ordonnée (unité)'

doc = Document('scatterplot_example', filepath='./examples/', doc_type='standalone')

doc += plot
Exemple #5
0
palette = holi(4)

for i, feature in enumerate(features):
    x, y = ax.collections[2 * i]._paths[
        0]._vertices.T  # Hacking into matplotlib objects to find the data defining the envelope

    q25, q50, q75 = np.percentile(data[i], [25, 50, 75])
    extrema = (i, i), (np.min(data[i]), np.max(data[i]))
    quartiles = (i, i), (q25, q75)
    median = (i, ), (q50, )

    plot.add_plot(x,
                  y,
                  'fill',
                  line_cap='round',
                  line_join='round',
                  fill_opacity=.5,
                  color=palette[i])
    plot.add_plot(*median,
                  'only marks',
                  mark_size='.4pt',
                  color=f'{palette[i]}!25')
    plot.add_plot(
        *extrema,
        color=f'{palette[i]}!50!black',
        line_cap='round',
        line_width='1pt',
    )
    plot.add_plot(
        *quartiles,
from python2latex import Template, Table, Plot

filepath = './examples/templating an existing file'
template = Template(filename='already_existing_file', filepath=filepath)

table = Table((4, 3))
table[1:, 0:] = [[i for _ in range(3)] for i in range(3)]
table[0] = 'Title'
table[0].add_rule()
table.caption = 'Here is a table caption.'

template.anchors['some_table'] = table

plot = Plot(plot_name='some_plot', plot_path=filepath)
plot.add_plot(list(range(10)), list(range(10)), 'red')
plot.caption = 'Here is a figure caption.'

template.anchors['some_figure'] = plot

template.render()