1

I am looking to overlay a scatter plot with a boxplot in matplotlib. I have created the chart but the x axes do not match--leading to the scatter plot showing dots that are shifted 1 tick to the left of the x axis for the boxplot. Below is my code.

fig, ax = plt.subplots()

ax.scatter(traits_5, data_df[traits_5].loc[y])
ax = greats_df[traits_5].boxplot ( showfliers=False , column=traits_5)

plt.ylabel ( 'Percentile Score' )
plt.title ( "Distribution of The Greats' Scores" )

ax.yaxis.set_major_formatter(mtick.PercentFormatter(1))

plt.show ()

Is it possible that the error is coming from the two different methods of plotting the data? I use matplotlib to plot the scatter and pandas to plot the boxplot. Matplotlib was plotting the rows on the xaxis, whereas I wanted the columns to be plotted along the x axis.

See outputted image below from above code.

enter image description here

Red
  • 26,798
  • 7
  • 36
  • 58
arhodes4
  • 21
  • 6

1 Answers1

0

Hard to investigate without having access to data, but if you just translate the x coordinates of your scatter plot, it should work:

ax.scatter([x+1 for x in traits_5], data_df[traits_5].loc[y])
Ali Hassaine
  • 579
  • 5
  • 19