Estou tentando traçar um gráfico de barras com 2 eixos y diferentes e o mesmo eixo x.
O mais próximo que cheguei do sucesso com o seguinte código:
fig = plt.figure() # Create matplotlib figure
ax = fig.add_subplot(111) # Create matplotlib axes
ax2 = ax.twinx() # Create another axes that shares the same x-axis as ax.
width = 0.4
final_df['GDP Value'].plot(kind='bar', color='red', ax=ax, width=width, position=1)
final_df['Homicides per 100 people'].plot(kind='bar', color='blue', ax=ax2, width=width, position=0)
ax.set_ylabel('GDP Value')
ax2.set_ylabel('Homicides per 100 people')
plt.show()
Mas como vocês podem ver na imagem abaixo o eixo x é o índice do meu DF, mas gostaria que fosse uma coluna específica, chamada 'Nome do País'. Tentei especificá-lo assim:
final_df['GDP Value'].plot(x=final_df['Country Name'],kind='bar', color='red', ax=ax, width=width, position=1)
Mas não funcionou.
Aqui está a estrutura do meu DF:
Agradeço antecipadamente, vocês são os melhores.