Home > Software engineering >  Data Visulation Problem With Bar Plot and It's axes
Data Visulation Problem With Bar Plot and It's axes

Time:01-04

i have a problem. I will show it you with pictures and tables.

            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

My dataframe is like above and graph is like below. Graph

# 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()

The code is above. I want to show the same values in one bar. For example, MGROS, SOKM and BIMAS same values. How can i show it one bar and one xticks as with all three names one under the other?

CodePudding user response:

I solve this problem. Here is the code.

I only rearranged my dataframe.

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))
  •  Tags:  
  • Related