Exemplo n.º 1
0
 def action_plot(self):
     max_range = 6.28
     if 'range' in request.GET:
         max_range = float(request.GET['range'])
     # import things
     import numpy as np
     import matplotlib.pyplot as plt
     # determine x, sin(x) and cos(x)
     x = np.arange(0, max_range, 0.1)
     y1 = np.sin(x)
     y2 = np.cos(x)
     # make figure
     fig = plt.figure()
     fig.subplots_adjust(hspace = 0.5, wspace = 0.5)
     fig.suptitle('The legendary sine and cosine curves')
     # first subplot
     ax = fig.add_subplot(2, 1, 1)
     ax.plot(x, y1, 'b')
     ax.plot(x, y1, 'ro')
     ax.set_title ('y = sin(x)')
     ax.set_xlabel('x')
     ax.set_ylabel('y')
     # second subplot
     ax = fig.add_subplot(2, 1, 2)
     ax.plot(x, y2, 'b')
     ax.plot(x, y2, 'ro')
     ax.set_title ('y = cos(x)')
     ax.set_xlabel('x')
     ax.set_ylabel('y')
     # make canvas
     return draw_matplotlib_figure(fig)
Exemplo n.º 2
0
                                    tup = tup + ([dimension_mean] * len(xx.ravel()) , )
                            Z = classifier.predict(np.c_[tup])
                            Z = Z.reshape(xx.shape)
                            ax.contourf(xx, yy, Z)
                            # scatter-plot the data
                            ax.scatter(x, y, c=target, cmap=plt.cm.gist_rainbow)
                            ax.set_title (first_dimension + ' vs ' + second_dimension + ' ('+caption+')')
                            ax.set_xlabel(first_dimension)
                            ax.set_ylabel(second_dimension)
                            subplot_index += 1
                            second_dimension_index += 1
                        first_dimension_index += 1
                        second_dimension_start_index += 1
                # make canvas
                file_name = 'classification/plot_'+str(np.random.randint(10000))+str(time.time())+'.png'
                plot_url = draw_matplotlib_figure(fig,file_name,'example')
            except Exception, e:
                result['success'] = False
                result['message'] = 'Unexpected error while creating plot : '+ e.message
            if not result['success']:
                return json.dumps(result)

        # initiate false positive, false negative, true positive, and true negative
        training_false_positive = {}
        training_false_negative = {}
        training_true_positive = {}
        training_true_negative = {}
        testing_false_positive = {}
        testing_false_negative = {}
        testing_true_positive = {}
        testing_true_negative = {}