# necessary packages from matplotlib import pyplot as plt import numpy as np # input the data left_points = [2, 3] # -1 class right_points = [6, 6.5, 8.3] # +1 class # graphing parameters font = {'size':16} tickfont = {'size':10} marker_style = dict(linestyle = 'none', markersize = 10, markeredgecolor = 'k') plt.rcParams['savefig.facecolor'] = '#c0c0c0' # set up the axes and ticks fig, ax = plt.subplots() ax.set_aspect(1) ax.annotate('', xy = (10, 0), xytext = (-.05, 0), arrowprops = {'arrowstyle':'->, head_width = 0.2', 'lw':1, 'facecolor':'k'}, va = 'center', zorder = -1, **font) ax.annotate('$x$', xy = (10.2, 0), xytext = (10.2, 0), va = 'center', **font) ax.annotate('', xy = (0, 1.7), xytext = (0, -1.7), arrowprops = {'arrowstyle':'-', 'lw':1, 'facecolor':'k'}, va = 'center') plt.xticks(np.arange(2, 9, 2), **tickfont) # plot the data ax.plot(left_points, np.zeros(len(left_points)), marker = "^", markerfacecolor = 'red', **marker_style, label = '$-1$') ax.plot(right_points, np.zeros(len(right_points)), marker = "s", markerfacecolor = 'blue', **marker_style, label='$+1$') ax.legend(loc = (0.75, 0.65), edgecolor = 'k', facecolor = 'None') # arrange the axes and box plt.gca().axes.get_yaxis().set_visible(False) plt.box(on = None) ax.spines['bottom'].set_position('zero') ax.spines['bottom'].set_color('none') plt.xlim([-1, 11]) plt.ylim([-2.2, 2.6]) # save the results fig.savefig('graph.png', bbox_inches = 'tight', pad_inches = -0.1) plt.show()