0

I am trying to make a profit vs sales chart in matplotlib, the profit line does appear on the chart but the sales line does not. here is my code

plt.figure(figsize = (30,20))
plt.plot(data.groupby('State')['Sales'].agg([sum]).sort_values('sum',ascending = False))
plt.plot(data.groupby('State')['Profit'].agg([sum]).sort_values('sum',ascending = False))

This is how i am expecting the chart should look:

1

This is how my chart looks:

2

This is head of Profit data

               sum
State   
California  76381.3871
New York    74038.5486
Washington  33402.6517
Michigan    24463.1876
Virginia    18597.9504

This is head of Sales data

                sum
State   
California      457687.6315
New York        310876.2710
Texas           170188.0458
Washington      138641.2700
Pennsylvania    116511.9140

also how do i make y bar in millions ?

UPDATE CODE:

fig, ax1 = plt.subplots()
color = 'tab:red'
ax1.set_xlabel('time (s)')
ax1.set_ylabel('exp', color=color)
ax1.plot( data.groupby('State')['Sales'].agg([sum]).sort_values('sum',ascending = False), color=color)
ax1.tick_params(axis='y', labelcolor=color)

ax2 = ax1.twinx()  

color = 'tab:blue'
ax2.set_ylabel('sin', color=color) 
ax2.plot(data.groupby('State')['Profit'].agg([sum]).sort_values('sum',ascending = False) , color=color)
ax2.tick_params(axis='y', labelcolor=color)

fig.tight_layout()
plt.show()
Sayaji
  • 127
  • 1
  • 1
  • 8

0 Answers0