How to print only the plot on python

Question:

I am executing the following piece of code to display a plot but the plot gives this description <matplotlib.legend.Legend at …> . I want only the plot to be displayed. Can anyone please help me how to remove the description and display only the plot.

plt.figure(figsize = (15,5))

ax = sns.lineplot(data=df1, x="x", y="y", hue="...",palette=['C6'])
ax =sns.lineplot(data=df2, x="x", y="y", hue="...",palette=['k'])

ax.set_ylabel("Power (W)")

plt.xticks(rotation=90)

legend_labels, _= ax.get_legend_handles_labels()

ax.legend(legend_labels, ['Day1','Day2'], 
          bbox_to_anchor=(1,1))

enter image description here

Asked By: Aishwarya

||

Answers:

Capture the return value from the last statement

_ = ax.legend(legend_labels, ['Day1','Day2'], bbox_to_anchor=(1,1))

It happens because Jupyter notebook always displays output from the last statement

Answered By: Vishnudev
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.