table in a figure

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

table in a figure

diedro
Dear all,

I have a scrip that put a table in a subfigure.
It works well. 
However, if I change the data it seems to not work anymore.
I would try to explain myself in a better way

this is the script:

def latex_table(celldata,rowlabel,collabel):
    table = r'\begin{table} \begin{tabular}{|1|'
    for c in range(0,len(collabel)):
        # add additional columns
        table += r'1|'
    table += r'} \hline'
    # provide the column headers
    for c in range(0,len(collabel)-1):
        table += collabel[c]
        table += r'&'
    table += collabel[-1]
    table += r'\\ \hline'

    # populate the table:
    # this assumes the format to be celldata[index of rows][index of columns]
    for r in range(0,len(rowlabel)):
        table += rowlabel[r]
        table += r'&'
        for c in range(0,len(collabel)-2):
            if not isinstance(celldata[r][c], basestring):
                table += str(celldata[r][c])
            else:
                table += celldata[r][c]
            table += r'&'

        if not isinstance(celldata[r][-1], basestring):
            table += str(celldata[r][-1])
        else:
            table += celldata[r][-1]
        table += r'\\ \hline'

    table += r'\end{tabular} \end{table}'

    return table

celldata = [[32, r'$\alpha$', 123],[200, 321, 50]]
rowlabel = [r'1st row', r'2nd row']
collabel = [r' sasas', r'$\alpha$', r'$\beta$', r'$\gamma$']


If I read instead "collabel" as
per_data=np.genfromtxt('2.csv',delimiter=',',names=True)
collabel = per_data.dtype.names

It does not print some values in collabel

Can anyone help me?
Really Really Thanks,

Diego


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: table in a figure

tcaswell
Diego,

It is hard to say much without also seeing your csv file.

What is the difference between the type and contents of the `collabel` in both cases?


Tom

On Sun, Sep 23, 2018 at 3:07 PM Diego Avesani <[hidden email]> wrote:
Dear all,

I have a scrip that put a table in a subfigure.
It works well. 
However, if I change the data it seems to not work anymore.
I would try to explain myself in a better way

this is the script:

def latex_table(celldata,rowlabel,collabel):
    table = r'\begin{table} \begin{tabular}{|1|'
    for c in range(0,len(collabel)):
        # add additional columns
        table += r'1|'
    table += r'} \hline'
    # provide the column headers
    for c in range(0,len(collabel)-1):
        table += collabel[c]
        table += r'&'
    table += collabel[-1]
    table += r'\\ \hline'

    # populate the table:
    # this assumes the format to be celldata[index of rows][index of columns]
    for r in range(0,len(rowlabel)):
        table += rowlabel[r]
        table += r'&'
        for c in range(0,len(collabel)-2):
            if not isinstance(celldata[r][c], basestring):
                table += str(celldata[r][c])
            else:
                table += celldata[r][c]
            table += r'&'

        if not isinstance(celldata[r][-1], basestring):
            table += str(celldata[r][-1])
        else:
            table += celldata[r][-1]
        table += r'\\ \hline'

    table += r'\end{tabular} \end{table}'

    return table

celldata = [[32, r'$\alpha$', 123],[200, 321, 50]]
rowlabel = [r'1st row', r'2nd row']
collabel = [r' sasas', r'$\alpha$', r'$\beta$', r'$\gamma$']


If I read instead "collabel" as
per_data=np.genfromtxt('2.csv',delimiter=',',names=True)
collabel = per_data.dtype.names

It does not print some values in collabel

Can anyone help me?
Really Really Thanks,

Diego

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


--
Thomas Caswell
[hidden email]

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users