I have the following box plots, which compares the time diffs. The data is collected from two different devices, which measure accelerometer data. I have done this analysis to compare the sampling frequencies.


The code is given here:

#calculate time delta and do a box plot

# array values multiplied by 1000 to convert to ms
timedelta1 = np.diff(time1)*1000
timedelta2 = np.diff(time2)*1000

# array values in seconds
timedelta1_sec = np.diff(time1)
timedelta2_sec = np.diff(time2)

plt.subplot(1, 2, 1)
plt.ylabel('$\Delta t$ in ms', fontsize=20)
plt.title('Delta sampling times $\\vec{{\\Delta t}}$', fontsize=20)

dict_boxplot_timediff = plt.boxplot([timedelta1, timedelta2],
                                    labels=[f'Device 1\n'
                                        #     f'{file1}\n'
                                            f'$\O \\vec{{\\Delta t}}$: {np.mean(timedelta1):.2f} ± {np.std(timedelta1):.2f} ms\n'
                                            f'Median $\\vec{{\\Delta t}}$: {np.median(timedelta1):.2f} ms \n'
                                            f'$\O f$: {1/np.mean(timedelta1_sec):.2f} Hz\n',

                                            f'Device 2\n'
                                        #     f'{file2} \n'
                                            f'$\O \\vec{{\\Delta t}}$: {np.mean(timedelta2):.2f} ± {np.std(timedelta2):.2f} ms\n'
                                            f'Median $\\vec{{\\Delta t}}$: {np.median(timedelta2):.2f} ms\n'
                                            f'$\O f$: {1/np.mean(timedelta2_sec):.2f} Hz\n'],

What methods exist so that I can have a better visualisation for the box plot on the right?


2 Answers 2


The boxplots you have are perfect. They clearly show that the two distributions differ radically: Device 2 has a lower median, lower first and third quartiles, actually lower values than almost all values of Device 1. Also, the spread within Device 2 is much smaller than within Device 1, which very often is a highly valuable piece of information all by itself.

All of this information would be lost if you changed the visualization.

Keep the visualization as it is, and be thankful you have so clearly different distributions. (You could look into beanplots or violin plots, especially if the many "outlier" dots in Device 1 mask many overplotted multiples. But whatever you do, ensure that the comparability of the plots remains.)


One quick way would be to have two y-axes, so that each boxplot scales its y-axis appropriately.

fig1, ax1 = plt.subplots()
ax1.set_title('Two Y-Axes BoxPlot')
ax2 = ax1.twinx()
ax2.boxplot(time2, positions=[3])

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.