【问题标题】:Data Visulation Problem With Bar Plot and It's axes条形图及其轴的数据可视化问题
【发布时间】:2022-01-27 05:24:28
【问题描述】:

我有问题。我会用图片和表格给你看。

            0
MGROS   4.983566
SOKM    4.983566
BIMAS   4.983566
POLHO   4.043808
VESBE   2.722698
ARCLK   2.722698
VESTL   2.722698
HURGZ   2.125138
YATAS   2.030432
SELEC   1.986755

我的数据框如上,图表如下。

# creating the bar plot
br = plt.bar(df.index, df.values.squeeze(), color =colorLIST,
        width = 0.9)
#for rect in br:
#    height = rect.get_height()
#    plt.text(rect.get_x() + rect.get_width() / 2.0, height, "%"+f'{height:.2f}', ha='center',         va='bottom', color = "#003C5F", fontsize = 5.5)
plt.xlabel("Sembol", color = "#7F2A3C", fontsize = 20)
plt.ylabel("Getiri", color = "#7F2A3C", fontsize = 20)
plt.xticks(rotation = 90, fontsize = 20 )
labels = plt.gca().get_xticklabels()
for i in range(len(labels)):
    labels[i].set_color(colorLIST[i])
plt.title("Global Sektörler", color = "#7F2A3C", fontsize = 20)

ax.spines['top'].set_color('#C2B280')
ax.spines['right'].set_color('none')
ax.spines['left'].set_smart_bounds(True)
ax.spines['bottom'].set_smart_bounds(True)
ax.yaxis.set_major_formatter(mtick.PercentFormatter())
#ax.grid(zorder=0)
#ax.xaxis.grid()
minor_locator = AutoMinorLocator(2)
plt.gca().xaxis.set_minor_locator(minor_locator)
plt.grid(which='minor')
plt.savefig("peers_company.png", dpi = 100)
plt.show()

代码如上。我想在一个栏中显示相同的值。例如,MGROS、SOKM 和 BIMAS 的值相同。我怎样才能显示一个条和一个 xticks,就像所有三个名称一个在另一个下一样?

【问题讨论】:

  • 这是一个数据准备问题。我不会尝试在可视化本身中解决这个问题

标签: python matplotlib graphics seaborn


【解决方案1】:

我解决了这个问题。这是代码。

我只是重新排列了我的数据框。

df['marker'] = (df[0] != df[0].shift()).cumsum()
df["TICKERS"] = df.index.tolist()
df = df.groupby('marker').agg({ 0: "first", "TICKERS": lambda x: list(x)})
df["VALUES"] = df[0].values
df.TICKERS = df.TICKERS.apply(lambda x : " ".join(x))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-13
    • 2012-09-19
    • 1970-01-01
    • 1970-01-01
    • 2021-02-26
    • 2023-03-25
    相关资源
    最近更新 更多