0

I am trying to define a function that takes two arguments which are scores(pandas.series) and ax(to determine where the plotting will be shown). However, when i'm trying to run it with some inputs, just blanks graphs are shown.

def plot_mi_scores(scores,ax):
    fig, (ax1,ax2) = plt.subplots(1,2)
    scores_asc = scores.sort_values(ascending=True)
    scores_values = scores.sort_values(ascending=True).values
    width = np.arange(len(scores_asc))
    ticks = list(scores_asc.index)
    axis=ax
    axis.barh(width, scores_values)
    axis.set_yticks(width, labels=ticks)
    axis.set_title("Mutual Information Scores")
    plt.show()

If i try to write the same code by typing different arguments directly into the code(below one), code is running as i expected. Is the way i am trying to plug the 'ax' argument into a function is false? how can i plug axis as an argument in the function.

    fig, (axis1,axis2) = plt.subplots(1,2)
    scores_asc = mi_scores.head(20).sort_values(ascending=True)
    scores_values = mi_scores.head(20).sort_values(ascending=True).values
    width = np.arange(len(scores_asc))
    ticks = list(scores_asc.index)
    axis1.barh(width, scores_values)
    axis1.set_yticks(width, labels=ticks)
    axis1.set_title("Mutual Information Scores")
    
    scores_asc = mi_scores.tail(20).sort_values(ascending=True)
    scores_values = mi_scores.tail(20).sort_values(ascending=True).values
    width = np.arange(len(scores_asc))
    ticks = list(scores_asc.index)
    axis2.barh(width, scores_values)
    axis2.set_yticks(width, labels=ticks)
    axis2.set_title("Mutual Information Scores")

enter image description here

Mehdihan
  • 9
  • 2
  • Get rid of `fig, (ax1,ax2) = plt.subplots(1,2)` inside `plot_mi_scores`, and use `ax.barh`, `ax.set_yticks`, `ax.set_title`. – BigBen Sep 23 '22 at 15:28

0 Answers0