如何控制prettyplotlib
条形图条的顺序?序在prettyplotlib条形图酒吧
从prettyplotlib==0.1.7
使用标准ppl.bar
我能得到一个条形图这样:
%matplotlib inline
import numpy as np
import prettyplotlib as ppl
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1)
counter = {1:1, 2:4, 3:9, 4:16, 5:25, 6:36, 7:49}
x, y = zip(*counter.items())
ppl.bar(ax, x , y, annotate=True, grid='y')
但是,如果我想要扭转x轴的酒吧,当我改变在x
名单,扭转棒的顺序,但不会标签:
ppl.bar(ax, list(reversed(x)) , y, annotate=True, grid='y')
我可以使用xticklabels
参数:
ppl.bar(ax, list(reversed(x)) , y, annotate=True, xticklabels=list('7654321'), grid='y')
但是,这并没有太多工作,它返回相同的权棒顺序错误x轴标签:
奇怪的是,当我逆转的xticklabels
,
ppl.bar(ax, list(reversed(x)) , y, annotate=True, xticklabels=list('1234567'), grid='y')
我有我需要的东西,但它现在的x
列表逆转奇怪,但xticklabels
不...
但如果我删除了逆转x
名单:
ppl.bar(ax, x , y, annotate=True, xticklabels=list('1234567'), grid='y')
我们得到的第一个相同的图作为ppl.bar(ax, x , y, annotate=True, grid='y')
...
为什么不正确扭转轴? https://stackoverflow.com/questions/2051744/reverse-y-axis-in-pyplot此外prettyplotlib似乎已被放弃多年,开发建议使用seaborn来代替。 –
啊...是的,seaborn维护得更好。 – alvas
请注意,尽管seaborn为matplotlib增加了很多样式功能,但其主要目的是轻松地与熊猫进行交互。所有的seaborn样式都可以从matplotlib中随时获得,除非您知道自己在做什么,否则我会建议使用matplotlib创建平常的样式。 – ImportanceOfBeingErnest