I want to add a progress bar that shows the progress of the executing function. The function imports data from a postgresql dataset and finally draw a bar_chart of percentages of each segments.
Here is my code:
class RfmTable:
def __init__(self,table_name,start_date,end_date):
self.table_name = table_name
self.start_date = start_date
self.end_date = end_date
self.quintiles = {}
def rfm_chart(self):
conn = psycopg2.connect(database=database_name, user=user_name,
password=password_info, host=host_info, port=port_info)
cursor = conn.cursor()
cursor.execute(...) #table information
a = cursor.fetchall()
# rfm analysis
# draw the chart
for i, bar in enumerate(bars):
value = bar.get_width()
if segments_counts.index[i] in ['重要价值用户']:
bar.set_color('firebrick')
ax.text(value,
bar.get_y() + bar.get_height()/2,
'{:,} ({:}%)'.format(int(value),
int(value*100/segments_counts.sum())),
va='center',
ha='left'
)
return plt.show()
So what is a good way to add a progress bar to the function?
