Color, zorder, and position of Bar plot #2965
-
I'm experimenting with the new interface and want to recreate this plot:
When I try to use the new interface:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I am pretty sure that your first example is labeling the y axis ticks incorrectly here. But if you just mean that the bars go from small to large when descending the y axis, you could do
so.Bar(color=...)
I think you want to add
In general, so.Bar(artist_kws={"zorder": ...}) You could also pass FWIW a lot of the other tweaks you're applying with messy matplotlib code can also be achieved through the p = (so.Plot(data=econ_df, x='Count', y='Type')
.add(so.Bar({"zorder": .5}, color="#006ba1"))
.on(f:=plt.figure())
.layout(algo=None)
.label(x="", y="")
.scale(x=so.Continuous().tick(every=2))
.theme({
"axes.facecolor": "w",
"axes.linewidth": 1.4,
"axes.edgecolor": ".2",
"axes.grid.axis": "x",
"grid.color": "#cbd5dc",
"grid.linewidth": 1.4,
**{f"axes.spines.{side}": False for side in ["bottom", "top", "right"]},
})
.plot()
)
ax = f.axes[0]
ax.yaxis.set_inverted(True)
ax.xaxis.set_tick_params(labeltop=True, labelbottom=False, pad=-1.2, labelsize=10)
display(p) I think you might be able to get the x ticks where / how you want them through rc params but I couldn't figure it out. |
Beta Was this translation helpful? Give feedback.
I am pretty sure that your first example is labeling the y axis ticks incorrectly here. But if you just mean that the bars go from small to large when descending the y axis, you could do
ax.yaxis.set_inverted(True)
which is what the seaborn categorical functions do by default (and probably what a Nominal scale will do at some point soon).I think you want to add
.layout(algo=None)
; perhaps the default should be to not apply a tight layout when passed an existing matplotlib object.