Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person

Categories

I am trying to publish a figure of a table that has been created from a dataframe for use in a report.

#Hard Coding example
TopTenSites = 238
RestOfSites = 387
#Creating a dataframe to pass into 
Proportion = pd.DataFrame({'Incidence': [TopTenSites, RestOfSites]},
             index=['Top 10 Sites', 'Rest of Sites'])

#Creating the table
fig, plot = plt.subplots(figsize = [3,2])
#plot.axis('off')
#Remove axis
plot.xaxis.set_visible(False) 
plot.yaxis.set_visible(False) 
#Creating the table
plot.table(cellText = Proportion.values, rowLabels = Proportion.index, loc = 'center', colLabels = 
Proportion.columns,cellLoc = 'center')
plt.savefig('Proportion.png')enter code here

The output in Jupyter notebook gives a table which looks like.

enter image description here

But the actual png produced by this code looks like

enter image description here

Does anyone know the formatting for a table so I can produce a png file that looks exactly like the output where the row labels are included.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
467 views
Welcome To Ask or Share your Answers For Others

1 Answer

Answer was to recreate the dataframe with a default numerical index

#Creating a dataframe to pass into 
Proportion = pd.DataFrame({'Sites': ['Top 10 Sites', 'Rest of Sites'],'Incidence': 
[TopTenSites, RestOfSites]})

#Creating the table plot
fig, plot = plt.subplots(figsize = [3,2])
plot.axis('off')
#Remove axis
plot.xaxis.set_visible(False) 
plot.yaxis.set_visible(False) 
#Creating the table
plot.table(cellText = Proportion.values,loc = 'center', colLabels = 
Proportion.columns, cellLoc = 'center')
plt.savefig('Proportion.png')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share

548k questions

547k answers

4 comments

32.8k users

...