Related to my recent question on printing \pm
in latex with pandas How to print a literal backslash to get \pm in a pandas data frame to generate a proper error bars in a latex table in python? I also wanted to display the table with the equations being shown correctly but instead I get the literal \pm
in my table (+ it has a weird shape).
Is there a way to convert my data frame with equations to a png latex directly from python and save it as an image?
script
import pandas as pd
# data = {'first_column': ['first_value', 'second_value', ...],
# 'second_column': ['first_value', 'second_value', ...],
# ....
# }
import pandas as pd
from uutils import put_pm_to_pandas_data
data = {
'Initialization': ['Random',
'Random2',
],
'Test Accuracy': ['0.200+-0.029',
'0.200+-0.0',
],
}
# - to pandas table
df = pd.DataFrame(data)
print(df)
# https://stackoverflow.com/questions/70009242/how-does-one-generate-latex-table-images-with-proper-equations-from-python-panda
# - to latex
data = put_pm_to_pandas_data(data)
df = pd.DataFrame(data)
print(df.to_latex(index=False, escape=False))
import matplotlib.pyplot as plt
import pandas as pd
from pandas.plotting import table
# ax = plt.subplot(111, frame_on=False) # no visible frame
ax = plt.gca()
ax.xaxis.set_visible(False) # hide the x axis
ax.yaxis.set_visible(False) # hide the y axis
# table(ax, df) # where df is your data frame
table(ax, df) # where df is your data frame
plt.show()
# plt.savefig('mytable.png')
related: