
我想用注釋繪制以下條形圖,并且我想將 x 標簽保持 45 度,以便于閱讀。我不確定為什么我的代碼不起作用。我已添加示例資料和所需的條形圖作為附件。我很欣賞你的建議!謝謝!
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
#sns.set(rc={"figure.dpi":300, 'savefig.dpi':300})
sns.set_context('notebook')
sns.set_style("ticks")
#sns.set_style('white')
sns.set_context("paper", font_scale = 2)
colors = ['b', 'g', 'r', 'c', 'm']
#sns.set(style="whitegrid")
#sns.set_palette(sns.color_palette(colors))
#fig, (ax1,ax2) = plt.subplots(1, 2, figsize=(16, 8))
#fig.subplots_adjust(wspace=0.3)
plots1 = sns.barplot(x="Model", y="G-mean", data=df_Aussel2014_5features, ax=ax1,palette='Spectral')
# Iterrating over the bars one-by-one
for bar in plots1.patches:
# Using Matplotlib's annotate function and
# passing the coordinates where the annotation shall be done
plots1.annotate(format(bar.get_height(), '.2f'),
(bar.get_x() bar.get_width() / 2,
bar.get_height()), ha='center', va='center',
size=10, xytext=(0, 5),
textcoords='offset points')
plt.show()
# Save figure
#plt.savefig('Aussel2014_5features.png', dpi=300, transparent=False, bbox_inches='tight')
我得到了以下影像。

uj5u.com熱心網友回復:
匯入matplotlib.pyplot為plt.plt.xticks(rotation=??45)
例子 :
import matplotlib.pyplot as plt
plt.xticks(rotation=??45)
uj5u.com熱心網友回復:
- 您正在使用面向物件的介面(例如
axes),所以不要混合使用plt.和axes.方法
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/354230.html標籤:Python 熊猫 matplotlib 海生 条形图
