generate functionMon, 17 Apr 2023

def plot_graph(chart_title, column_to_label): df=show_data.sort_values(by="Upload", ascending=False)[:5] ax = df.plot(kind='barh', figsize=(20,15), x="Name", rot=0) plt.title(chart_title, fontsize=20) plt.xlabel("") plt.ylabel("") plt.xticks(fontsize=20) plt.yticks(fontsize=20) #adding value labels in the center of each bar for p in ax.patches: ax.annotate(str(p.get_width()), (p.get_width() * 1.005, p.get_y() * 1.005)) ax.set_yticklabels(ax.get_yticklabels(), rotation=40, ha="right") plt.savefig(chart_title+'.pdf') #fig.autofmt_xdate() plot_graph("top 5 cities with the most records", "Number") transform this program to insert data frame below the graph in pdf before save.

import matplotlib.pyplot as plt import pandas as pd #fake data df = pd.DataFrame({'Name' : ['John', 'Jane', 'Peter', 'Chris'], 'Age' : [23, 26, 24, 22]}) #create figure and axis fig, ax = plt.subplots() #hide axes fig.patch.set_visible(False) ax.axis('off') ax.axis('tight') ax.table(cellText=df.values,colLabels=df.columns,loc='center') fig.tight_layout()

Questions about programming?Chat with your personal AI assistant