title: Plot SVM decision boundary
body: <p>The following code fits an SVM with polynomial kernel and plot the iris data and the decision boundary. The input X is using the first 2 columns of the data, sepal length and width. However I  am having difficulties reproducing the output with the 3rd and 4th columns as X, that is the petal length and width. How can I change the plot function for the code to work?  Thanks in advance.</p>
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from sklearn import datasets
  from sklearn.svm import SVC
  
  iris= datasets.load_iris()
  y= iris.target
  #X= iris.data[:, :2]  # sepal length and width
  X= iris.data[:, 2:]   # I tried a different X but it failed.
  
  # Ref: https://medium.com/all-things-ai/in-depth-parameter-tuning-for-svc-758215394769
  def plotSVC(title):
      # create a mesh to plot in
      x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
      y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
      h = (x_max / x_min)/100
      xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
      plt.subplot(1, 1, 1)
      Z = svm_mod.predict(np.c_[xx.ravel(), yy.ravel()])
      Z = Z.reshape(xx.shape)
      plt.contourf(xx, yy, Z, cmap=plt.cm.Paired, alpha=0.8)
      plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Paired)
      plt.xlabel('Sepal length')
      plt.ylabel('Sepal width')
      plt.xlim(xx.min(), xx.max())
      plt.title(title)
      plt.show()
  
  svm= SVC(C= 10, kernel='poly', degree=2, coef0=1, max_iter=500000)
  svm_mod= svm.fit(X,y)
  plotSVC('kernel='+ str('polynomial'))
  </code></pre>
  <p>The error:</p>
  <pre><code>  import sys
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-57-4515f111e34d&gt; in &lt;module&gt;()
        2 svm= SVC(C= 10, kernel='poly', degree=2, coef0=1, max_iter=500000)
        3 svm_mod= svm.fit(X,y)
  ----&gt; 4 plotSVC('kernel='+ str('polynomial'))
  
  &lt;ipython-input-56-556d4a22026a&gt; in plotSVC(title)
       10     Z = svm_mod.predict(np.c_[xx.ravel(), yy.ravel()])
       11     Z = Z.reshape(xx.shape)
  ---&gt; 12     plt.contourf(xx, yy, Z, cmap=plt.cm.Paired, alpha=0.8)
       13     plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Paired)
       14     plt.xlabel('Sepal length')
  
  ~/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in contourf(*args, **kwargs)
     2931                       mplDeprecation)
     2932     try:
  -&gt; 2933         ret = ax.contourf(*args, **kwargs)
     2934     finally:
     2935         ax._hold = washold
  
  ~/anaconda3/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
     1853                         &quot;the Matplotlib list!)&quot; % (label_namer, func.__name__),
     1854                         RuntimeWarning, stacklevel=2)
  -&gt; 1855             return func(ax, *args, **kwargs)
     1856 
     1857         inner.__doc__ = _add_data_doc(inner.__doc__,
  
  ~/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_axes.py in contourf(self, *args, **kwargs)
     6179             self.cla()
     6180         kwargs['filled'] = True
  -&gt; 6181         contours = mcontour.QuadContourSet(self, *args, **kwargs)
     6182         self.autoscale_view()
     6183         return contours
  
  ~/anaconda3/lib/python3.6/site-packages/matplotlib/contour.py in __init__(self, ax, *args, **kwargs)
      844         self._transform = kwargs.pop('transform', None)
      845 
  --&gt; 846         kwargs = self._process_args(*args, **kwargs)
      847         self._process_levels()
      848 
  
  ~/anaconda3/lib/python3.6/site-packages/matplotlib/contour.py in _process_args(self, *args, **kwargs)
     1414                 self._corner_mask = mpl.rcParams['contour.corner_mask']
     1415 
  -&gt; 1416             x, y, z = self._contour_args(args, kwargs)
     1417 
     1418             _mask = ma.getmask(z)
  
  ~/anaconda3/lib/python3.6/site-packages/matplotlib/contour.py in _contour_args(self, args, kwargs)
     1472             args = args[1:]
     1473         elif Nargs &lt;= 4:
  -&gt; 1474             x, y, z = self._check_xyz(args[:3], kwargs)
     1475             args = args[3:]
     1476         else:
  
  ~/anaconda3/lib/python3.6/site-packages/matplotlib/contour.py in _check_xyz(self, args, kwargs)
     1508             raise TypeError(&quot;Input z must be a 2D array.&quot;)
     1509         elif z.shape[0] &lt; 2 or z.shape[1] &lt; 2:
  -&gt; 1510             raise TypeError(&quot;Input z must be at least a 2x2 array.&quot;)
     1511         else:
     1512             Ny, Nx = z.shape
  
  TypeError: Input z must be at least a 2x2 array.
  </code></pre>