def _plot(self): self.figure.clear() self.canvas.draw() self.buttonSave.setEnabled(False) if self.pt is None and self.rectangle is None: return if self.parameter is None or self.coverage is None or self.dataset is None: return canvasLayers = [] try: allCoverageLayers = layers._layers[self.dataset][self.coverage] except KeyError: return for layerdef in allCoverageLayers: source = layerdef.source() time = parser.parse(layerdef.time()) try: layer = layerFromSource(source) canvasLayers.append((layerdef, time)) except WrongLayerSourceException: pass if not canvasLayers: return minDate = None maxDate = None minY = None maxY = None if self.filter: if self.filter[0] is not None: minDate = self.filter[0] if self.filter[1] is not None: maxDate = self.filter[1] minY = self.filter[2] or None maxY = self.filter[3] or None try: bands = allCoverageLayers[0].bands() if self.rectangle is None: self.data = {} startProgressBar("Retrieving plot data", len(canvasLayers)) for (i, (layerdef, time)) in enumerate(canvasLayers): if ((minDate is not None and time < minDate) or (maxDate is not None and time > maxDate)): continue start = timelib.time() layer = layerdef.layer() v = self.parameter.value(layer, self.pt, bands) end = timelib.time() logger.info( "Plot data for layer %i retrieved in %s seconds" % (i, str(end - start))) setProgressValue(i + 1) if v is not None: self.data[time] = [(v, (self.pt.x(), self.pt.y()))] closeProgressBar() if not self.data: return y = [v[0][0] for v in self.data.values()] ymin = min(y) ymax = max(y) else: self.data = {} startProgressBar("Retrieving plot data", len(canvasLayers)) for (i, (layerdef, time)) in enumerate(canvasLayers): if ((minDate is not None and time < minDate) or (maxDate is not None and time > maxDate)): continue start = timelib.time() layer = layerdef.layer() if not self.rectangle.intersects(layer.extent()): continue rectangle = self.rectangle.intersect(layer.extent()) xsteps = int(rectangle.width() / layer.rasterUnitsPerPixelX()) ysteps = int(rectangle.height() / layer.rasterUnitsPerPixelY()) filename = layerdef.layerFile(rectangle) roi = layers.getBandArrays(filename) end = timelib.time() logger.info( "ROI data for layer %i retrieved in %s seconds" % (i, str(end - start))) start = timelib.time() setProgressValue(i + 1) self.data[time] = [] for col in range(xsteps): x = rectangle.xMinimum( ) + col * layer.rasterUnitsPerPixelX() for row in range(ysteps): y = rectangle.yMinimum( ) + row * layer.rasterUnitsPerPixelY() pixel = QgsPoint(col, row) value = self.parameter.value(roi, pixel, bands) if value: self.data[time].append((value, (x, y))) end = timelib.time() logger.info( "Plot data computed from ROI data in %s seconds" % (str(end - start))) closeProgressBar() if not self.data: return y = [[v[0] for v in lis] for lis in self.data.values()] ymin = min([min(v) for v in y]) ymax = max([max(v) for v in y]) xmin = min(self.data.keys()) xmax = max(self.data.keys()) if self.filter is None: self.plotDataChanged.emit(xmin, xmax, ymin, ymax) self.dataToPlot = copy.deepcopy(self.data) if self.filter: for key, values in self.data.iteritems(): for v in values[::-1]: if ((minY is not None and v[0] < minY) or (maxY is not None and v[0] > maxY)): try: self.dataToPlot[key].remove(v) except: pass datesToRemove = [] for key, values in self.dataToPlot.iteritems(): if not values: datesToRemove.append(key) for d in datesToRemove: del self.dataToPlot[d] axes = self.figure.add_subplot(1, 1, 1) x = matplotlib.dates.date2num(self.dataToPlot.keys()) if self.rectangle is None: y = [v[0][0] for v in self.dataToPlot.values() if v] axes.scatter(self.dataToPlot.keys(), y) else: sortedKeys = sorted(self.dataToPlot.keys()) y = [[v[0] for v in self.dataToPlot[k]] for k in sortedKeys] axes.boxplot(y) axes.set_xticklabels( [str(d).split(" ")[0] for d in sortedKeys], rotation=70) self.figure.autofmt_xdate() except Exception, e: traceback.print_exc() closeProgressBar() return
import matplotlib.pyplot as plt from matplotlib import rcParams from matplotlib import axes as ax from mpl_toolkits.mplot3d import Axes3D import numpy as np x, y, z, vx, vy, vz = np.loadtxt('./coordAa.dat.txt', unpack=True) print(len(x)) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(x, y, z, c='r', marker='.', s=0.1) #Axes3D.scatter(x,y,z) ax.set_xlabel('X [kpc]') ax.set_ylabel('Y [kpc]') ax.set_zlabel('Z [kpc]') #plt.axis([-1500., 1500., -1500., 1500, -1500, 1500]) ax.set_xlim3d(-1500, 1500) ax.set_ylim3d(-1500, 1500) ax.set_zlim3d(-1500, 1500) plt.show() radius = sorted([ np.sqrt(i**2 + j**2 + k**2) for i, j, k in zip(x, y, z) if np.sqrt(i**2 + j**2 + k**2) <= 300 ]) max_radius = max(radius) min_radius = min(radius)
model = (clf1, clf2, clf3, MyCls) models = (clf.fit(X, y) for clf in model) # title for the plots titles = ('CSOVO', 'CSOVA', 'CSCS', 'Apportioned SVM') # Set-up 2x2 grid for plotting. #plt.figure() fig, sub = plt.subplots(2, 2) plt.subplots_adjust(wspace=0.4, hspace=0.4) xx, yy = make_meshgrid(X[:, 0], X[:, 1]) for clf, title, ax in zip(models, titles, sub.flatten()): plot_contours(ax, clf, xx, yy, cmap=plt.cm.coolwarm, alpha=0.8) ax.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.coolwarm, s=20, edgecolors='k') ax.set_xlim(xx.min(), xx.max()) ax.set_ylim(yy.min(), yy.max()) # ax.set_xlabel('x label') # ax.set_ylabel('Sepal width') ax.set_xticks(()) ax.set_yticks(()) ax.set_title(title) plt.show()
#TODO this is just temporary def find_nearest(array, value): idx = (np.abs(array - value)).argmin() return array[idx] closest_freq = find_nearest(freq_array, orbital_f) closest_conf = find_nearest(confidence_array, result_ds) plot.healpix_heatmap(np.log10( freqdict[closest_freq].map_dictionary[closest_conf]), cmap='viridis_r') #--------------------------- ax.scatter(math.radians(input_phi), math.radians(input_theta), marker='o', s=40, color='orangered', linewidths=1.0, edgecolors='k', zorder=8) #TOD make colorbar an axes cb = plt.colorbar(orientation='horizontal') cb.ax.tick_params(labelcolor='w', color='w') plt.suptitle( '{0}% Characteristic Strain Upper Limit at {1}Hz, '.format( closest_conf, closest_freq) + '$\log_{{10}}h_{{{0}}}$'.format(closest_conf), y=0.05, color='w') plt.grid(linestyle='dotted', color='k') plt.tight_layout() PNG_name = uuid4().hex
points = [( 0.07826526, -0.8631922 , -0.49877228), (-0.02999477, -0.96742597, -0.25137087), ( 0.06420691, -0.9818318 , -0.17856034), ( 0.16057571, -0.95586931, -0.24602703), ( 0.24508727, -0.95988891, -0.13618192), ( 0.40681028, -0.88751077, -0.21640245), ( 0.44190865, -0.81611357, -0.37239145), ( 0.47401636, -0.79000325, -0.38884876), ( 0.07826526, -0.8631922 , -0.49877228)] axes.plot(*[[p[i] for p in points] for i in range(3)], color='r') query = (0.29210493879571187, -0.8867057671346513, -0.35836794954530027) axes.scatter(*[[query[i]] for i in range(3)], color='g') ext = (-0.21032302, 0.93088621, 0.29868896) axes.scatter(*[[ext[i]] for i in range(3)], color='g') for span in [[(0.47401636, -0.79000325, -0.38884876), (0.07826526, -0.8631922, -0.49877228)], [(-0.02999477, -0.96742597, -0.25137087), (0.06420691, -0.9818318, -0.17856034)]]: axes.plot(*[[p[i] for p in span] for i in range(3)], color='b') for isect in ((-0.38326894491900027, 0.8212662350427856, 0.4226425050078664), (0.38326894491900027, -0.8212662350427856, -0.4226425050078664)): axes.scatter(*[[isect[i]] for i in range(3)], color='m') for isect in ((-0.05822094898415143, 0.9813342391376142, 0.1832851117673903), (0.05822094898415143, -0.9813342391376142, -0.1832851117673903)):
import mglearn as ml import matplotlib.pyplot as plt import matplotlib.axes as ax from sklearn.neighbors import KNeighborsClassifier x,y = ml.datasets.make_forge() fig,axes = plt.subplots(1,3,figsize=(10,3)) for n_neighbors , ax in zip([1,3,9],axes): clf = KNeighborsClassifier(n_neighbors=n_neighbors).fit(x,y) ml.plots.plot_2d_separator(clf , x , fill=True , eps=0.5 , ax=ax , alpha=.4) ax.scatter(x[:,0] , x[:,1] , c=y , s=60 , cmap=ml.cm2) ax.set_title("%d neighbor(s) " % n_neighbors) plt.show()
cmap=pyplot.cm.gray_r, extent=extent, interpolation='nearest') pyplot.subplot(324) H, xedges, yedges = numpy.histogram2d( [s.color for s in r.stars], [s.magnitude for s in r.stars], normed=True, bins=(100,100)) extent = [xedges[0], xedges[-1] * 10, yedges[0], yedges[-1]] pyplot.imshow(H, cmap=pyplot.cm.gray_r, extent=extent, interpolation='nearest') from mpl_toolkits.mplot3d import axes3d axes = pyplot.subplot(325, projection='3d') axes.scatter([s.color for s in d.stars], [s.magnitude for s in d.stars], [s.offset for s in d.stars]) axes = pyplot.subplot(326, projection='3d') axes.scatter([s.color for s in r.stars], [s.magnitude for s in r.stars], [s.offset for s in r.stars]) pyplot.show()