title: Plotting Threshold (precision_recall curve) matplotlib/sklearn.metrics
body: <p>I am trying to plot the thresholds for my precision/recall curve. I am just using the MNSIT data, with the example from the book Hands On Machine Learning with scikit-learn, keras, and TensorFlow. Trying to train the model to detect the image of 5's. I don't know how much of the code you need to see. I have made my confusion matrix for the training set and have calculated the precision and recall values, along with the thresholds. I have plotted the pre/rec curve and the example in the book says to add axis label, ledged, grid and highlight the thresholds but the code cuts off in the book where I placed an asterisk below. I was able to figure out all but how to get the thresholds to show up on the plot. I have included a picture of what the graph in the book looks like vs what I have.
  This is what the book shows:</p>
  <p><a href="https://i.stack.imgur.com/MuRHQ.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/MuRHQ.jpg" alt="enter image description here" /></a>
  vs my graph:</p>
  <p><a href="https://i.stack.imgur.com/kcwmN.png" rel="noreferrer"><img src="https://i.stack.imgur.com/kcwmN.png" alt="enter image description here" /></a></p>
  <p>I can't get that red dotline with two threshold points to show up. Does anyone have any idea how I would do this? Here is my code below:</p>
  <pre><code>from sklearn.metrics import precision_recall_curve
  
  precisions, recalls, thresholds = precision_recall_curve(y_train_5, y_scores)
  
  def plot_precision_recall_vs_thresholds(precisions, recalls, thresholds):
      plt.plot(thresholds, precisions[:-1], &quot;b--&quot;, label=&quot;Precision&quot;)
      plt.plot(thresholds, recalls[:-1], &quot;g--&quot;, label=&quot;Recall&quot;)
      plt.xlabel(&quot;Threshold&quot;)
      plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.)
      plt.grid(b=True, which=&quot;both&quot;, axis=&quot;both&quot;, color='gray', linestyle='-', linewidth=1)
  
  plot_precision_recall_vs_thresholds(precisions, recalls, thresholds)
  plt.show()
  </code></pre>
  <p>I know there's a decent amount of questions on here about this with sklearn but none seem to cover getting that red line to show up. I would greatly appreciate the help!</p>