1

I have the following Chartify code snippet.

ch = chartify.Chart(blank_labels=True, x_axis_type='categorical', layout="slide_100%")
ch.set_title("Grouped bar chart")
ch.set_subtitle(
    "Pass a list to group by multiple factors. Color grouped by 'fruit'")
ch.plot.bar(
    data_frame=df_chart,
    categorical_columns=["month", "account"],
    numeric_column="bill",
    color_column="account",
    categorical_order_by=sort_order
)
ch.plot.text(
    data_frame=df_chart,
    categorical_columns=["month", "account"],
    numeric_column='bill',
    text_column='billdisp',
    color_column='account',
    categorical_order_by=sort_order
)
ch.axes.hide_xaxis()
ch.show('png')

It produces the following chart:

enter image description here

Each of the bars correspond to 'account' column. As you can see the X Axis is already crowded as it is.

How do I add a legend to the chart ? I would like to tell that blue = account-1, green = account-2, orange = account 3.

1 Answers1

0

You can fake it by adding 3 extra empty plots which are there only to add legend of your choice.

# Previous code

plt.plot([], [], label='Account 1', c='b')
plt.plot([], [], label='Account 2', c='g')
plt.plot([], [], label='Account 3', c='orange')
plt.legend()
plt.show()
meW
  • 3,832
  • 7
  • 27