Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 箱线图及;散点图:消失的X记号_Python_Pandas_Boxplot - Fatal编程技术网

Python 箱线图及;散点图:消失的X记号

Python 箱线图及;散点图:消失的X记号,python,pandas,boxplot,Python,Pandas,Boxplot,我有一些数据可以绘制散点图: df_1 = pd.DataFrame({'X':[3,3,3,3], 'Y':[1,2,3,4]}) 以及更多数据,以便在同一轴上绘制方框图: np.random.seed(1234) df_2 = pd.DataFrame(np.random.randn(10,1), columns=['Y']) df_2['X'] = [2,2,3,3,3,2,2,2,2,2] 我试过: #

我有一些数据可以绘制散点图:

df_1 = pd.DataFrame({'X':[3,3,3,3],
                     'Y':[1,2,3,4]})
以及更多数据,以便在同一轴上绘制方框图:

np.random.seed(1234)
df_2 = pd.DataFrame(np.random.randn(10,1),
                   columns=['Y'])

df_2['X'] = [2,2,3,3,3,2,2,2,2,2]
我试过:

# Scatter
ax = df_1.plot.scatter(x='X',
                       y='Y',
                       c='k',
                       s=100)

props = dict(linewidth=4)

# Boxplot
ax = df_2.boxplot(by='X',
                  boxprops     = props,
                  medianprops  = props,
                  whiskerprops = props,
                  capprops     = props,
                  ax=ax)

plt.suptitle("")
ax.set_title("")
plt.xlabel('X')
plt.ylabel('Y')

font = {'weight' : 'normal',
        'size'   : 30}
plt.rc('font', **font)

plt.xlim([0,4])

fig = plt.gcf()
fig.set_size_inches(10,7)

plt.show()
plt.xticks([0,1,2,3,4],[0,1,2,3,4])
但我得到了:

我的x轴没有显示所有的刻度,它显示的刻度在错误的位置。我怎样才能校正x轴呢?

我试过:

# Scatter
ax = df_1.plot.scatter(x='X',
                       y='Y',
                       c='k',
                       s=100)

props = dict(linewidth=4)

# Boxplot
ax = df_2.boxplot(by='X',
                  boxprops     = props,
                  medianprops  = props,
                  whiskerprops = props,
                  capprops     = props,
                  ax=ax)

plt.suptitle("")
ax.set_title("")
plt.xlabel('X')
plt.ylabel('Y')

font = {'weight' : 'normal',
        'size'   : 30}
plt.rc('font', **font)

plt.xlim([0,4])

fig = plt.gcf()
fig.set_size_inches(10,7)

plt.show()
plt.xticks([0,1,2,3,4],[0,1,2,3,4])
这给了我:

这已经纠正了x轴,但方框图仍然位于错误的位置。

我尝试了:

# Scatter
ax = df_1.plot.scatter(x='X',
                       y='Y',
                       c='k',
                       s=100)

props = dict(linewidth=4)

# Boxplot
ax = df_2.boxplot(by='X',
                  boxprops     = props,
                  medianprops  = props,
                  whiskerprops = props,
                  capprops     = props,
                  ax=ax)

plt.suptitle("")
ax.set_title("")
plt.xlabel('X')
plt.ylabel('Y')

font = {'weight' : 'normal',
        'size'   : 30}
plt.rc('font', **font)

plt.xlim([0,4])

fig = plt.gcf()
fig.set_size_inches(10,7)

plt.show()
plt.xticks([0,1,2,3,4],[0,1,2,3,4])
这给了我:

这已更正了x轴,但长方体图仍位于沿x轴的错误位置