Generation

generate functionTue, 21 Mar 2023

There is a Pandas dataframe: water nutri mineral 0 1 1 2 1 2 2 1 2 3 4 1 3 4 6 3 4 2 5 2 5 4 6 4 6 2 7 2 7 4 5 4 8 5 4 5 9 2 5 4 10 3 6 3 11 4 7 2 12 2 4 3 13 1 3 2 14 3 5 3 15 4 5 1 16 3 6 3 17 2 5 4 18 5 4 5 19 1 3 1 Construct a vertical bar graph comparing these values, where the x-axis is index and the y-axis is the value of each column

import matplotlib.pyplot as plt from pandas.plotting import table fig, ax = plt.subplots(figsize=(10, 2)) # set size frame ax.xaxis.set_visible(False) # hide the x axis ax.yaxis.set_visible(False) # hide the y axis ax.set_frame_on(False) # no visible frame, uncomment if size is ok tabla = table(ax, df, loc='upper right', colWidths=[0.17]*len(df.columns)) # where df is your data frame tabla.auto_set_font_size(False) # Activate set fontsize manually tabla.set_fontsize(12) # if ++fontsize is necessary ++colWidths tabla.scale(1.2, 1.2) # change size table plt.savefig('table.png', transparent=True)

Questions about programming?Chat with your personal AI assistant