Issue
This is my code:
column1 = ['Measured Set', '1. set', '2. set', '3. set']
column2= ['Breached parameter (number of breaches, %)' ]
column3 = ['Breached parameter (number of breaches, %)']
for j in range(NOT):
column2.append(report_str[0][j])
column3.append(report_str[1][j])
data = {
'Sensor': column1,
'Sensor 1': column2,
'Sensor 2': column3,
}
df = pd.DataFrame(data)
df
report_str
is a list, filled with strings from which I copy certain strings into the table.
I tried this to save the table with this code:
ax = df.plot()
fig = ax.get_figure()
fig.savefig('asdf.png')
But I get an error: "Empty 'DataFrame': no numeric data to plot".
This is my output table that I want to save:
Could anyone help me with this issue?
Solution
First of all your columns lists have to be the same length. You may plot table with matplotlib and table
function from pandas.
import pandas as pd
import matplotlib.pylab as plt
from pandas.tools.plotting import table
# I add None value to align all lists
column1 = ['Measured Set', '1. set', '2. set', '3. set']
column2= ['Breached parameter (number of breaches, %)', None, None,None ]
column3 = ['Breached parameter (number of breaches, %)', None, None,None]
data = {
'Sensor': column1,
'Sensor 1': column2,
'Sensor 2': column3,
}
df = pd.DataFrame(data)
print(df)
# set fig size
fig, ax = plt.subplots(figsize=(12, 3))
# no axes
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
# no frame
ax.set_frame_on(False)
# plot table
tab = table(ax, df, loc='upper right')
# set font manually
tab.auto_set_font_size(False)
tab.set_fontsize(8)
# save the result
plt.savefig('table.png')
Answered By - Serenity
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.