我有一些堆积的条形图,看起来像这样
在Matplotlib中这是可能的(合理的)吗
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
test1 = np.array([51, 13.8, 15.5, np.NaN])
test2 = np.array([40.3, 30.4, 13.8, 15.5])
df = pd.DataFrame(dict(test1 = test1,
test2 = test2),
columns = ["test1","test2"]).T
ax = df.plot.barh(stacked = True, cmap = "coolwarm", edgecolor = "black", lw = 1, width = 0.8, figsize = (6,4))
plt.show()
首先,条的边缘是黑色的,因为您在对
df.plot.barh
的调用中设置了edgecolor = "black"
。删除这意味着将没有edgecolor。您需要将每个条的edgecolor设置为条的facecolor您可以通过遍历矩形面片(使用} 和^{} 将edgecolor设置为facecolor来实现
ax.patches
获得)并使用^{它给出:
相关问题 更多 >
编程相关推荐