如何在Jupyter中更正折线图起点?

时间:2020-09-13 16:51:41

标签: python pandas matplotlib plot jupyter-notebook

从图像中可以看到,该图表中的线从2而不是1开始。有人可以帮我解决这个问题吗?我应该更改使其从1开始吗?enter image description here

Child

1 个答案:

答案 0 :(得分:1)

尝试一下:

from numpy.random import randint
import pandas as pd
import matplotlib.pyplot as plt


df1=pd.DataFrame([[1,2,3,4,5,6,7,8,9,10,11],list(randint(400,500,11)),randint(400,500,11)]).T
df1.columns=['CustomerS','value1','value2']
#df1=df1.set_index('CustomerS')
df2=pd.DataFrame([[1,2,3,4,5,6,7,8,9,10,11],randint(0,10,11)]).T
df2.columns=['CustomerS','value1']
#df2=df2.set_index('CustomerS')

df3 = df1.merge(df2,on='CustomerS') #merging two dataframes
df3.columns = ['CustomerS','value1','value2','value3']
df3.iloc[:,:-1].plot.bar(x='CustomerS',stacked=True)

df3.iloc[:,-1].plot(x='CustomerS',secondary_y=True, color='r')
plt.legend(loc=2)

输出enter image description here