Prison break question

Hi Sahil,

Thanks so much for sharing the guided project. I have a question. Can you please explain to me what is going on in this statement:

ax = plt.barh(*zip(*d.items()), height=.5)

Basically, this part of the code has me really stumped

rectangles = ax.patches
    for rectangle in rectangles:
        x_value = rectangle.get_width()
        y_value = rectangle.get_y() + rectangle.get_height() / 2
        space = 5
        ha = 'left'
        label = "{}".format(x_value)
        if x_value > 0:
            plt.annotate(
                label,
                (x_value, y_value),
                xytext=(space, 0),
                textcoords="offset points",
                va='center',
                ha=ha)

    axes.tick_params(tick1On=False)

Thank you!

1 Like

Hi @ayesha.s.abduljalil

Welcome to the DQ community! This post was first created in Jan 2022. Are you still looking for an answer?

My question is because concepts like a dictionary, zip method, the matplotlib library etc. may not have been covered before this project. These topics are taken up in the latter part of the course.

I can help you with some statements like we apply the zip(* method on the dictionary items with dictionary being a key-value pair to segregate the keys and values. The keys would then represent the y-axis and values will make up the x-axis values (since it’s a horizontal bar plot barh) etc. etc. but it may confuse you rather than helping you.

If you have covered these topics by now and are still in doubt then let the community know. We will be glad to help you.

Awaiting your reply.