Seaborn BarPlot 反转 y 轴并将 x 轴保持在图表区域的底部
Seaborn BarPlot invert y axis and keep x axis on bottom of chart area
在 Excel 中,我可以绘制如下所示的图表:
让它看起来像这样:
通过反转 Y 轴并将 "Horizontal Axis Crosses" 设置为 "max"。
我想在 Seaborn 中做同样的事情。我可以使用 .invert_yaxis()
翻转 y_axis 但我无法像在 Excel.
中那样将条形图保留在图表底部
import seaborn as sns
barplot = sns.barplot(x='abc'
,y='def'
,data=df
,ci=None
)
barplot.invert_yaxis()
barplot.figure
产生如下内容:
如何将条形图从顶部移动到底部?
我正在使用 Python 3.6 和 seaborn 0.7.1
我的问题似乎与这个问题类似,但这个问题不清楚并且没有答案:
Pyplot - Invert Y labels without inverting bar chart
seaborn.barplot
是 pyplot.bar
的包装器,您可以使用 pyplot.bar
创建具有倒置 Y 轴和从图表底部到较低值的条形图在 y 轴上:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
df = pd.DataFrame({"x":range(5), "y": [1,1.2,1.4,1.6,1.8]})
plt.bar(df.x, 2*np.ones(len(df))-df.y, bottom= df.y )
plt.gca().invert_yaxis()
plt.ylim(2,0)
plt.show()
我发现你可以简单地做:
plt.ylim(reversed(plt.ylim()))
这让您可以继续使用 Seaborn。
在 Excel 中,我可以绘制如下所示的图表:
让它看起来像这样:
通过反转 Y 轴并将 "Horizontal Axis Crosses" 设置为 "max"。
我想在 Seaborn 中做同样的事情。我可以使用 .invert_yaxis()
翻转 y_axis 但我无法像在 Excel.
import seaborn as sns
barplot = sns.barplot(x='abc'
,y='def'
,data=df
,ci=None
)
barplot.invert_yaxis()
barplot.figure
产生如下内容:
如何将条形图从顶部移动到底部?
我正在使用 Python 3.6 和 seaborn 0.7.1
我的问题似乎与这个问题类似,但这个问题不清楚并且没有答案: Pyplot - Invert Y labels without inverting bar chart
seaborn.barplot
是 pyplot.bar
的包装器,您可以使用 pyplot.bar
创建具有倒置 Y 轴和从图表底部到较低值的条形图在 y 轴上:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
df = pd.DataFrame({"x":range(5), "y": [1,1.2,1.4,1.6,1.8]})
plt.bar(df.x, 2*np.ones(len(df))-df.y, bottom= df.y )
plt.gca().invert_yaxis()
plt.ylim(2,0)
plt.show()
我发现你可以简单地做:
plt.ylim(reversed(plt.ylim()))
这让您可以继续使用 Seaborn。