简体   繁体   中英

Title using relplot in Seaborn

I am using the following code to plot some Covid Data. Not being able to get a title for the graph, though. Nor am I able to annotate the graph with the text for the source. Please help.

sns.set(style='darkgrid')
#plot a scatterplot with 'Confirmed' on x and 'Deaths' on y-axis
sns.relplot(x = 'log_Confirmed', y= 'log_Deaths', kind='scatter',
            data=df3, col='Province_State', col_wrap=3)
plt.title('COVID- 19 Deaths  - Select US States ')
plt.annotate('Source: JHU Coronavirus Resource Center', (0,0), (0, -40),
             xycoords='axes fraction', textcoords='offset points',
             va='top', fontsize=6)

sns.relplot() is a figure-level function that creates several axes objection in a FacetGrid . plt.XXXX() functions, on the other hand, act on the "current" Axes objection, which is generally the last axes created.

If you want to add stuff to the figure, you should use figure level functions, for instance Figure.suptitle() , or use annotate in figure coordinates:

tips = sns.load_dataset('tips')
g = sns.relplot(x="total_bill", y="tip",
                hue="day", col="time", data=tips)
g.fig.suptitle('Figure title', fontsize=20, fontweight='bold')
plt.annotate("Annotation in figure coordinates", xy=(0,0), xycoords='figure fraction', va='bottom', ha='left')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM