在seaborn中为每个子图添加文本

时间:2017-01-06 17:46:38

标签: python seaborn

我在seaborn制作条形图,我想在每个子图中添加一些文字。我知道如何向整个图形添加文本,但我想访问每个子图并添加文本。我正在使用此代码:

import seaborn as sns
import pandas as pd

sns.set_style("whitegrid")

col_order=['Deltaic Plains','Hummock and Swale', 'Sand Dunes']

g = sns.FacetGrid(final, col="Landform", col_wrap=3,despine=False, sharex=False,col_order=col_order)

    g = g.map(sns.barplot, 'Feature', 'Importance')

    [plt.setp(ax.get_xticklabels(), rotation=45) for ax in g.axes.flat]

    for ax, title in zip(g.axes.flat, col_order):
        ax.set_title(title)

    g.fig.text(0.85, 0.85,'Text Here', fontsize=9) #add text

这给了我这个: enter image description here

1 个答案:

答案 0 :(得分:14)

在for循环期间,您已经为function setComments($conn) { if (isset($_POST['commentSubmit'])){ $users = $_POST['users']; $date = $_POST['date']; $message = $_POST['message']; $id = $_POST['id']; $sql = "INSERT INTO comments (users, date, message, id) VALUES ('$users', '$date', '$message', '$id')"; $result = $conn->query($sql); } } function getComments($conn) { $id = intval($_POST['id']); $sql = ("SELECT * FROM comments WHERE id = $id ORDER BY cid DESC"); $result = $conn->query($sql); while($row = $result->fetch_assoc()) { echo "<div class='comment-box'><p>"; echo $row['users']."<br>"; echo $row['date']."<br>"; echo nl2br($row['message']); echo "</p> </div>"; } } 提供了每个子图。

ax