seaborn - How can I decrease the width of a boxplot rectangle?
问题描述
I've made a boxplot:
I would like to decrease the width of the blue/orange rectangle to get a width like the blue/orange rectangles in this boxplot:
My goal is it to decrease the total width of the boxplot so that it takes less space in a document / I can have text flow beside the plot picture.
Code so far:
ax_v = sns.boxplot(x="hasTopic", y="sentiment_sum", data=videos, orient="v")
ax_v.set(xticklabels=["ohne", "mit"])
ax_v.set(ylim=(-4, 4))
plt.xlabel('Themenbezug Videos', fontsize=14)
plt.ylabel('Sentiment', fontsize=14)
plt.show()
How can I do that in Seaborn?
解决方案
plt.figure(figsize=(3.4, 4)) # <- this line
ax_v = sns.boxplot(x="hasTopic", y="sentiment_sum", data=videos, width=0.5, orient="v")
ax_v.set(xticklabels=["ohne", "mit"])
ax_v.set(ylim=(-4, 4))
plt.xlabel('Themenbezug Videos', fontsize=14)
plt.ylabel('Sentiment', fontsize=14)
plt.show()
解决了。
要使用自定义颜色为每个矩形着色,请使用:
my_pal = {0: "#3399ff", 1: "#f1c40f"} # x="hasTopic" has value 0 or 1
plt.figure(figsize=(3.4, 4), dpi=800)
ax_c = sns.violinplot(x="hasTopic", y="sentiment_sum", palette=my_pal, width=0.7, orient="v", data=channels)
ax_c.yaxis.set_major_locator(ticker.MultipleLocator(tick_spacing))
#ax_v = sns.swarmplot(x="hasTopic", y="sentiment_sum", data=comments, color=".25")
ax_c.set(xticklabels=["ohne", "mit"])
ax_c.set(ylim=(-4, 4))
plt.xlabel('Themenbezug Channels', fontsize=14)
plt.ylabel('Sentiment', fontsize=14)
plt.tight_layout()
plt.show()
推荐阅读
- ios - Bazel 不构建 ios mediapipe 示例
- python - 将可教机器模型转换为 tflite 格式
- flutter - 如何解决“IconData”不是“Widget”类型的子类型?
- python - 使用 python 中的文件创建二维网格
- leaflet - 将传单 js 更新为 1.xx 后无法单击多边形
- python - 无法在python中显示随机单词
- ios - SKCloudServiceController().requestUserToken 在 iOS 14.2 上冻结
- python - 从 numpy 中的给定形状生成所有可广播的形状
- python - python 3:只能将str(不是“字节”)连接到str
- java - GridPane 的图像显示在 JavaFX 中?