1
votes

I am using Scipy.

I have heartrate(arrays) and max_Distance Data from my running sessions. I try to make a boxplot of my heartrate over the Date when I did the Run, and in the same Graph a Dot-Plot of my max-Distance.

I can make the Dot-Plots or the Boxplots, but I cannot combine them into one plot with the same x-Axis.

Another Problem I came along: the Boxplots write their 'x-Position' as a label at the x-Axis. But with a few Dates they overlap and I cannot read anything. I would prefere if Boxplot does not plot any label in the x-axis and only a few linear spread Dates are writen (not sure if it's clear what I am talking about, I mean like the values in a normal x-y-Dot-Diagram where not every point has his position marked at the x-axis.)

I tried to make a minimal example of my Code but unfortunately I couldn't create the data variables. So i Try to show my Data situation (sorry, for the bad mini-example). In this Mini-Example both plots on it's own work fine but if I try to plot both of them at the same time I see only the Boxplot.

setDate = array(['2016-05-10T01:00:00.000000000+0100',
                 '2016-05-20T02:00:00.000000000+0200',
                 '2016-05-24T02:00:00.000000000+0200'], dtype='datetime64[ns]')

setDistance = [5.8,
               6.8,
               6.5]

setPlace_color = ['b',
                  'r',
                  'b']

heartrate_bins = [2     133.0
                  3     145.0
                  5     142.0
                  Name: Heartrate, dtype: float64,
                  17     96.0
                  19    135.0
                  20    140.0
                  Name: Heartrate, dtype: float64,
                  21    142.0
                  22    145.0
                  Name: Heartrate, dtype: float64]

Code

# Create the Figure
fig = plt.figure()
ax1 = fig.add_subplot(111)

# Plot the Distance
for i in range(0, 4): ax1.plot(setDate[i], setDistance[i], 'o', color=setPlace_color[i])

# Calculate the x-Position for the Boxplot
z = np.array([0]).astype(setDate.dtype)
plt_dates = (setDate - z) / np.timedelta64(1,'D')

# Plot the HR with Boxplots
ax2 = ax1.twinx()
ax2.boxplot(heartrate_bins, positions = plt_dates, sym='')
Your hearrate_bins' is something I cannot copy-paste and therefore test. I think you want to use ax1.twiny()' and not `ax1.twinx()'.oschoudhury