def onData(self, value): """ Executed when selected item data is modified. """ plt = Plot.getPlot() if not plt: self.updateUI() return if not self.skip: self.skip = True name = self.names[self.item] obj = self.objs[self.item] x = self.form.x.value() y = self.form.y.value() s = self.form.s.value() # x/y labels only have one position control if name.find('x label') >= 0: self.form.y.setValue(x) elif name.find('y label') >= 0: self.form.x.setValue(y) # title and labels only have one size control if name.find('title') >= 0 or name.find('label') >= 0: obj.set_position((x, y)) obj.set_size(s) # legend have all controls else: Plot.legend(plt.legend, (x, y), s) plt.update() self.skip = False
def onOffset(self, value): """Executed when axes offsets have been modified.""" # Ensure that we can work plt = Plot.getPlot() if not plt: self.updateUI() return axesList = [plt.axes] if self.form.all.isChecked(): axesList = plt.axesList # Set new offset for axes in axesList: # For some reason, modify spines offset erase axes labels, so we # need store it in order to regenerate later x = axes.get_xlabel() y = axes.get_ylabel() for loc, spine in axes.spines.iteritems(): if loc in ['bottom', 'top']: spine.set_position(('outward', self.form.xOffset.value())) if loc in ['left', 'right']: spine.set_position(('outward', self.form.yOffset.value())) # Now we can restore axes labels Plot.xlabel(unicode(x)) Plot.ylabel(unicode(y)) plt.update()
def onData(self): """Executed when the selected item data is modified.""" if not self.skip: self.skip = True plt = Plot.getPlot() if not plt: self.updateUI() return # Ensure that selected serie exist if self.item >= len(Plot.series()): self.updateUI() return # Set label serie = Plot.series()[self.item] if (self.form.isLabel.isChecked()): serie.name = None self.form.label.setEnabled(False) else: serie.name = self.form.label.text() self.form.label.setEnabled(True) # Set line style and marker style = self.form.style.currentIndex() linestyles = list(Line2D.lineStyles.keys()) serie.line.set_linestyle(linestyles[style]) marker = self.form.marker.currentIndex() markers = list(Line2D.markers.keys()) serie.line.set_marker(markers[marker]) # Set line width and marker size serie.line.set_linewidth(self.form.width.value()) serie.line.set_markersize(self.form.size.value()) plt.update() # Regenerate series labels self.setList() self.skip = False
def updateUI(self): """ Setup UI controls values if possible """ plt = Plot.getPlot() self.form.items.setEnabled(bool(plt)) self.form.label.setEnabled(bool(plt)) self.form.isLabel.setEnabled(bool(plt)) self.form.style.setEnabled(bool(plt)) self.form.marker.setEnabled(bool(plt)) self.form.width.setEnabled(bool(plt)) self.form.size.setEnabled(bool(plt)) self.form.color.setEnabled(bool(plt)) self.form.remove.setEnabled(bool(plt)) if not plt: self.plt = plt self.form.items.clear() return self.skip = True # Refill list if self.plt != plt or len(Plot.series()) != self.form.items.count(): self.plt = plt self.setList() # Ensure that have series if not len(Plot.series()): self.form.label.setEnabled(False) self.form.isLabel.setEnabled(False) self.form.style.setEnabled(False) self.form.marker.setEnabled(False) self.form.width.setEnabled(False) self.form.size.setEnabled(False) self.form.color.setEnabled(False) self.form.remove.setEnabled(False) return # Set label serie = Plot.series()[self.item] if serie.name is None: self.form.isLabel.setChecked(True) self.form.label.setEnabled(False) self.form.label.setText("") else: self.form.isLabel.setChecked(False) self.form.label.setText(serie.name) # Set line style and marker self.form.style.setCurrentIndex(0) for i, style in enumerate(Line2D.lineStyles.keys()): if style == serie.line.get_linestyle(): self.form.style.setCurrentIndex(i) self.form.marker.setCurrentIndex(0) for i, marker in enumerate(Line2D.markers.keys()): if marker == serie.line.get_marker(): self.form.marker.setCurrentIndex(i) # Set line width and marker size self.form.width.setValue(serie.line.get_linewidth()) self.form.size.setValue(serie.line.get_markersize()) # Set color color = Colors.colorConverter.to_rgb(serie.line.get_color()) self.form.color.setStyleSheet( "background-color: rgb({}, {}, {});".format( int(color[0] * 255), int(color[1] * 255), int(color[2] * 255))) self.skip = False
def onNew(self): """Executed when new axes must be created.""" # Ensure that we can work plt = Plot.getPlot() if not plt: self.updateUI() return Plot.addNewAxes() self.form.axId.setValue(len(plt.axesList) - 1) plt.update()
def Activated(self): from FreeCAD.Plot import Plot plt = Plot.getPlot() if not plt: msg = QtGui.QApplication.translate( "plot_console", "The grid must be activated on top of a plot document", None) FreeCAD.Console.PrintError(msg + "\n") return flag = plt.isGrid() Plot.grid(not flag)
def accept(self): plt = Plot.getPlot() if not plt: msg = QtGui.QApplication.translate( "plot_console", "Plot document must be selected in order to save it", None) App.Console.PrintError(msg + "\n") return False path = self.form.path.text() size = (self.form.sizeX.value(), self.form.sizeY.value()) dpi = self.form.dpi.value() Plot.save(path, size, dpi) return True
def create(self, title, function, xlength, xname, xunit, xscale, yname, yunit, yscale, numxpoints): # Initialize from FreeCAD.Plot import Plot self.title = title self.function = function # This is assumed to be always a SegmentFunction self.xlength = xlength self.xname = xname self.xunit = xunit self.xscale = xscale self.yname = yname self.yunit = yunit self.yscale = yscale self.numxpoints = numxpoints # Create a plot window self.win = Plot.figure(title) # Get the plot object from the window self.thePlot = Plot.getPlot() # Format the plot object Plot.xlabel("$%s$ [%s]" % (xname, xunit)) Plot.ylabel("$%s$ [%s]" % (yname, yunit)) Plot.grid(True) # Calculate points (self.xpoints, self.ypoints) = self.function.evaluate(self.xlength, self.numxpoints) # Create plot self.plot()
def onRemove(self): """Executed when the data serie must be removed.""" plt = Plot.getPlot() if not plt: self.updateUI() return # Ensure that selected serie exist if self.item >= len(Plot.series()): self.updateUI() return # Remove serie Plot.removeSerie(self.item) self.setList() self.updateUI() plt.update()
def updateUI(self): """ Setup UI controls values if possible """ plt = Plot.getPlot() self.form.axId.setEnabled(bool(plt)) self.form.title.setEnabled(bool(plt)) self.form.titleSize.setEnabled(bool(plt)) self.form.xLabel.setEnabled(bool(plt)) self.form.xSize.setEnabled(bool(plt)) self.form.yLabel.setEnabled(bool(plt)) self.form.ySize.setEnabled(bool(plt)) if not plt: return # Ensure that active axes is correct index = min(self.form.axId.value(), len(plt.axesList) - 1) self.form.axId.setValue(index) # Store data before starting changing it. ax = plt.axes t = ax.get_title() x = ax.get_xlabel() y = ax.get_ylabel() tt = ax.title.get_fontsize() xx = ax.xaxis.label.get_fontsize() yy = ax.yaxis.label.get_fontsize() # Set labels self.form.title.setText(t) self.form.xLabel.setText(x) self.form.yLabel.setText(y) # Set font sizes self.form.titleSize.setValue(tt) self.form.xSize.setValue(xx) self.form.ySize.setValue(yy)
def setupUi(self): self.form.items = self.widget(QtGui.QListWidget, "items") self.form.x = self.widget(QtGui.QDoubleSpinBox, "x") self.form.y = self.widget(QtGui.QDoubleSpinBox, "y") self.form.s = self.widget(QtGui.QDoubleSpinBox, "size") self.retranslateUi() self.updateUI() QtCore.QObject.connect( self.form.items, QtCore.SIGNAL("currentRowChanged(int)"), self.onItem) QtCore.QObject.connect( self.form.x, QtCore.SIGNAL("valueChanged(double)"), self.onData) QtCore.QObject.connect( self.form.y, QtCore.SIGNAL("valueChanged(double)"), self.onData) QtCore.QObject.connect( self.form.s, QtCore.SIGNAL("valueChanged(double)"), self.onData) QtCore.QObject.connect( Plot.getMdiArea(), QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"), self.onMdiArea) return False
def __init__(self, title, periods): try: from FreeCAD.Plot import Plot except ImportError: try: from freecad.plot import Plot except ImportError: msg = QtGui.QApplication.translate( "ship_console", "Plot module is disabled, so I cannot perform the plot", None) FreeCAD.Console.PrintWarning(msg + '\n') return True self.is_angle = title.lower() in ['roll', 'pitch', 'yaw'] dirs = list(DIRS) dirs.append(2.0 * np.pi) periods = [0] + [t.getValueAs('s').Value for t in periods] self.plt = Plot.figure(title) self.plt.axes.remove() fig = self.plt.fig ax = fig.subplots(subplot_kw=dict(projection='polar')) self.plt.axesList = [ax] self.plt.setActiveAxes(-1) self.r, self.theta = np.meshgrid(periods, dirs) self.rao = np.zeros((len(dirs), len(periods))) self.phase = np.zeros((len(dirs), len(periods))) cs = ax.contourf(self.theta, self.r, self.rao, cmap='jet') self.label = 'm / m' if not self.is_angle else 'deg / m' self.cb = fig.colorbar(cs, label=self.label) self.plt.update() self.spreadSheet(title)
def onMdiArea(self, subWin): """Executed when a new window is selected on the mdi area. Keyword arguments: subWin -- Selected window. """ plt = Plot.getPlot() if plt != subWin: self.updateUI()
def setupUi(self): self.form.axId = self.widget(QtGui.QSpinBox, "axesIndex") self.form.title = self.widget(QtGui.QLineEdit, "title") self.form.titleSize = self.widget(QtGui.QSpinBox, "titleSize") self.form.xLabel = self.widget(QtGui.QLineEdit, "titleX") self.form.xSize = self.widget(QtGui.QSpinBox, "xSize") self.form.yLabel = self.widget(QtGui.QLineEdit, "titleY") self.form.ySize = self.widget(QtGui.QSpinBox, "ySize") self.retranslateUi() # Look for active axes if can axId = 0 plt = Plot.getPlot() if plt: while plt.axes != plt.axesList[axId]: axId = axId + 1 self.form.axId.setValue(axId) self.updateUI() QtCore.QObject.connect(self.form.axId, QtCore.SIGNAL('valueChanged(int)'), self.onAxesId) QtCore.QObject.connect(self.form.title, QtCore.SIGNAL("editingFinished()"), self.onLabels) QtCore.QObject.connect(self.form.xLabel, QtCore.SIGNAL("editingFinished()"), self.onLabels) QtCore.QObject.connect(self.form.yLabel, QtCore.SIGNAL("editingFinished()"), self.onLabels) QtCore.QObject.connect(self.form.titleSize, QtCore.SIGNAL("valueChanged(int)"), self.onFontSizes) QtCore.QObject.connect(self.form.xSize, QtCore.SIGNAL("valueChanged(int)"), self.onFontSizes) QtCore.QObject.connect(self.form.ySize, QtCore.SIGNAL("valueChanged(int)"), self.onFontSizes) QtCore.QObject.connect( Plot.getMdiArea(), QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"), self.onMdiArea) return False
def onColor(self): """ Executed when color palette is requested. """ plt = Plot.getPlot() if not plt: self.updateUI() return # Ensure that selected serie exist if self.item >= len(Plot.series()): self.updateUI() return # Show widget to select color col = QtGui.QColorDialog.getColor() # Send color to widget and serie if col.isValid(): serie = plt.series[self.item] self.form.color.setStyleSheet( "background-color: rgb({}, {}, {});".format( col.red(), col.green(), col.blue())) serie.line.set_color((col.redF(), col.greenF(), col.blueF())) plt.update()
def onLabels(self): """ Executed when labels have been modified. """ plt = Plot.getPlot() if not plt: self.updateUI() return Plot.title(unicode(self.form.title.text())) Plot.xlabel(unicode(self.form.xLabel.text())) Plot.ylabel(unicode(self.form.yLabel.text())) plt.update()
def onFontSizes(self, value): """ Executed when font sizes have been modified. """ # Get apply environment plt = Plot.getPlot() if not plt: self.updateUI() return ax = plt.axes ax.title.set_fontsize(self.form.titleSize.value()) ax.xaxis.label.set_fontsize(self.form.xSize.value()) ax.yaxis.label.set_fontsize(self.form.ySize.value()) plt.update()
def updateUI(self): """ Setup UI controls values if possible """ plt = Plot.getPlot() self.form.path.setEnabled(bool(plt)) self.form.pathButton.setEnabled(bool(plt)) self.form.sizeX.setEnabled(bool(plt)) self.form.sizeY.setEnabled(bool(plt)) self.form.dpi.setEnabled(bool(plt)) if not plt: return fig = plt.fig size = fig.get_size_inches() dpi = fig.get_dpi() self.form.sizeX.setValue(size[0]) self.form.sizeY.setValue(size[1]) self.form.dpi.setValue(dpi)
def onAxesId(self, value): """Executed when axes index is modified.""" if not self.skip: self.skip = True # No active plot case plt = Plot.getPlot() if not plt: self.updateUI() self.skip = False return self.form.axId.setMaximum(len(plt.axesList)) if self.form.axId.value() >= len(plt.axesList): self.form.axId.setValue(len(plt.axesList) - 1) # Send new control to Plot instance plt.setActiveAxes(self.form.axId.value()) self.updateUI() self.skip = False
def setupUi(self): self.form.path = self.widget(QtGui.QLineEdit, "path") self.form.pathButton = self.widget(QtGui.QPushButton, "pathButton") self.form.sizeX = self.widget(QtGui.QDoubleSpinBox, "sizeX") self.form.sizeY = self.widget(QtGui.QDoubleSpinBox, "sizeY") self.form.dpi = self.widget(QtGui.QSpinBox, "dpi") self.retranslateUi() home = os.getenv('USERPROFILE') or os.getenv('HOME') self.form.path.setText(os.path.join(home, "plot.png")) self.updateUI() QtCore.QObject.connect(self.form.pathButton, QtCore.SIGNAL("pressed()"), self.onPathButton) QtCore.QObject.connect( Plot.getMdiArea(), QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"), self.onMdiArea) return False
def plot(self, roll, gz): """ Plot the GZ curve. Position arguments: roll -- List of roll angles (in degrees). gz -- List of GZ values (in meters). """ try: from FreeCAD.Plot import Plot except ImportError: try: from freecad.plot import Plot except ImportError: msg = QtGui.QApplication.translate( "ship_console", "Plot module is disabled, so I cannot perform the plot", None) FreeCAD.Console.PrintWarning(msg + '\n') return True plt = Plot.figure('GZ') self.plt = plt gz_plot = Plot.plot(roll, gz, 'GZ curve') gz_plot.line.set_linestyle('-') gz_plot.line.set_linewidth(1.0) gz_plot.line.set_color((0.0, 0.0, 0.0)) self.gz = gz_plot ax = Plot.axes() Plot.xlabel(r'$\phi \; [\mathrm{deg}]$') Plot.ylabel(r'$GZ \; [\mathrm{m}]$') ax.xaxis.label.set_fontsize(20) ax.yaxis.label.set_fontsize(20) Plot.grid(True) plt.update() return False
def onDims(self, value): """Executed when axes dims have been modified.""" # Ensure that we can work plt = Plot.getPlot() if not plt: self.updateUI() return axesList = [plt.axes] if self.form.all.isChecked(): axesList = plt.axesList # Set new dimensions xmin = self.form.xMin.value() / 100.0 xmax = self.form.xMax.value() / 100.0 ymin = self.form.yMin.value() / 100.0 ymax = self.form.yMax.value() / 100.0 for axes in axesList: axes.set_position([xmin, ymin, xmax - xmin, ymax - ymin]) plt.update()
def setList(self): """Setup the UI control values if it is possible.""" mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskPanel") self.form.items = self.widget(QtGui.QListWidget, "items") self.form.items.clear() series = Plot.series() for i in range(0, len(series)): serie = series[i] string = 'serie ' + str(i) + ': ' if serie.name is None: string = string + '\"No label\"' else: string = string + serie.name self.form.items.addItem(string) # Ensure that selected item is correct if len(series) and self.item >= len(series): self.item = len(series) - 1 self.form.items.setCurrentIndex(self.item)
def setupUi(self): self.form.items = self.widget(QtGui.QListWidget, "items") self.form.label = self.widget(QtGui.QLineEdit, "label") self.form.isLabel = self.widget(QtGui.QCheckBox, "isLabel") self.form.style = self.widget(QtGui.QComboBox, "lineStyle") self.form.marker = self.widget(QtGui.QComboBox, "markers") self.form.width = self.widget(QtGui.QDoubleSpinBox, "lineWidth") self.form.size = self.widget(QtGui.QSpinBox, "markerSize") self.form.color = self.widget(QtGui.QPushButton, "color") self.form.remove = self.widget(QtGui.QPushButton, "remove") self.retranslateUi() self.fillStyles() self.updateUI() QtCore.QObject.connect(self.form.items, QtCore.SIGNAL("currentRowChanged(int)"), self.onItem) QtCore.QObject.connect(self.form.label, QtCore.SIGNAL("editingFinished()"), self.onData) QtCore.QObject.connect(self.form.isLabel, QtCore.SIGNAL("stateChanged(int)"), self.onData) QtCore.QObject.connect(self.form.style, QtCore.SIGNAL("currentIndexChanged(int)"), self.onData) QtCore.QObject.connect(self.form.marker, QtCore.SIGNAL("currentIndexChanged(int)"), self.onData) QtCore.QObject.connect(self.form.width, QtCore.SIGNAL("valueChanged(double)"), self.onData) QtCore.QObject.connect(self.form.size, QtCore.SIGNAL("valueChanged(int)"), self.onData) QtCore.QObject.connect(self.form.color, QtCore.SIGNAL("pressed()"), self.onColor) QtCore.QObject.connect(self.form.remove, QtCore.SIGNAL("pressed()"), self.onRemove) QtCore.QObject.connect( Plot.getMdiArea(), QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"), self.onMdiArea) return False
def updateUI(self): """Setup the UI control values if it is possible.""" plt = Plot.getPlot() self.form.items.setEnabled(bool(plt)) self.form.x.setEnabled(bool(plt)) self.form.y.setEnabled(bool(plt)) self.form.s.setEnabled(bool(plt)) if not plt: self.plt = plt self.form.items.clear() return # Refill items list only if Plot instance have been changed if self.plt != plt: self.plt = plt self.plt.update() self.setList() # Get data for controls name = self.names[self.item] obj = self.objs[self.item] if name.find('title') >= 0 or name.find('label') >= 0: p = obj.get_position() x = p[0] y = p[1] s = obj.get_size() if name.find('x label') >= 0: self.form.y.setEnabled(False) self.form.y.setValue(x) elif name.find('y label') >= 0: self.form.x.setEnabled(False) self.form.x.setValue(y) else: x = plt.legPos[0] y = plt.legPos[1] s = obj.get_texts()[-1].get_fontsize() # Send it to controls self.form.x.setValue(x) self.form.y.setValue(y) self.form.s.setValue(s)
def onAlign(self, value): """Executed when axes align have been modified.""" # Ensure that we can work plt = Plot.getPlot() if not plt: self.updateUI() return axesList = [plt.axes] if self.form.all.isChecked(): axesList = plt.axesList # Set new alignment for axes in axesList: if self.form.xAlign.currentIndex() == 0: axes.xaxis.tick_bottom() axes.spines['bottom'].set_color((0.0, 0.0, 0.0)) axes.spines['top'].set_color('none') axes.xaxis.set_ticks_position('bottom') axes.xaxis.set_label_position('bottom') else: axes.xaxis.tick_top() axes.spines['top'].set_color((0.0, 0.0, 0.0)) axes.spines['bottom'].set_color('none') axes.xaxis.set_ticks_position('top') axes.xaxis.set_label_position('top') if self.form.yAlign.currentIndex() == 0: axes.yaxis.tick_left() axes.spines['left'].set_color((0.0, 0.0, 0.0)) axes.spines['right'].set_color('none') axes.yaxis.set_ticks_position('left') axes.yaxis.set_label_position('left') else: axes.yaxis.tick_right() axes.spines['right'].set_color((0.0, 0.0, 0.0)) axes.spines['left'].set_color('none') axes.yaxis.set_ticks_position('right') axes.yaxis.set_label_position('right') plt.update()
def onRemove(self): """Executed when axes must be deleted.""" # Ensure that we can work plt = Plot.getPlot() if not plt: self.updateUI() return # Don't remove first axes if not self.form.axId.value(): msg = QtGui.QApplication.translate("plot_console", "Axes 0 can not be deleted", None) App.Console.PrintError(msg + "\n") return # Remove axes ax = plt.axes ax.set_axis_off() plt.axesList.pop(self.form.axId.value()) # Ensure that active axes is correct index = min(self.form.axId.value(), len(plt.axesList) - 1) self.form.axId.setValue(index) plt.update()
def plot(self, x, y, disp, xcb, ship): """ Perform the areas curve plot. @param x X coordinates. @param y Transversal areas. @param disp Ship displacement. @param xcb Buoyancy center length. @param ship Active ship instance. @return True if error happens. """ try: from FreeCAD.Plot import Plot except ImportError: try: from freecad.plot import Plot except ImportError: msg = QtGui.QApplication.translate("ship_console", "Plot module is disabled", None) FreeCAD.Console.PrintWarning(msg + '\n') return True areas = Plot.plot(x, y, 'Transversal areas') areas.line.set_linestyle('-') areas.line.set_linewidth(2.0) areas.line.set_color((0.0, 0.0, 0.0)) # Get perpendiculars data Lpp = ship.Length.getValueAs('m').Value FPx = 0.5 * Lpp APx = -0.5 * Lpp maxArea = max(y) # Plot perpendiculars FP = Plot.plot([FPx, FPx], [0.0, maxArea]) FP.line.set_linestyle('-') FP.line.set_linewidth(1.0) FP.line.set_color((0.0, 0.0, 0.0)) AP = Plot.plot([APx, APx], [0.0, maxArea]) AP.line.set_linestyle('-') AP.line.set_linewidth(1.0) AP.line.set_color((0.0, 0.0, 0.0)) # Add annotations for prependiculars ax = Plot.axes() ax.annotate('AP', xy=(APx + 0.01 * Lpp, 0.01 * maxArea), size=15) ax.annotate('AP', xy=(APx + 0.01 * Lpp, 0.95 * maxArea), size=15) ax.annotate('FP', xy=(FPx + 0.01 * Lpp, 0.01 * maxArea), size=15) ax.annotate('FP', xy=(FPx + 0.01 * Lpp, 0.95 * maxArea), size=15) # Add some additional data addInfo = ("$XCB = {0} \\; \\mathrm{{m}}$\n" "$Area_{{max}} = {1} \\; \\mathrm{{m}}^2$\n" "$\\bigtriangleup = {2} \\; \\mathrm{{tons}}$".format( xcb.getValueAs("m").Value, maxArea, disp.getValueAs("kg").Value / 1000.0)) ax.text(0.0, 0.01 * maxArea, addInfo, verticalalignment='bottom', horizontalalignment='center', fontsize=20) # Write axes titles Plot.xlabel(r'$x \; \mathrm{m}$') Plot.ylabel(r'$Area \; \mathrm{m}^2$') ax.xaxis.label.set_fontsize(20) ax.yaxis.label.set_fontsize(20) # Show grid Plot.grid(True) # End return False
def plot(self, l, z, v): """ Perform the areas curve plot. @param l Percentages of filling level. @param z Level z coordinates. @param v Volume of fluid. @return True if error happens. """ try: from FreeCAD.Plot import Plot except ImportError: try: from freecad.plot import Plot except ImportError: msg = QtGui.QApplication.translate( "ship_console", "Plot module is disabled, so I cannot perform the plot", None) FreeCAD.Console.PrintWarning(msg + '\n') return True plt = Plot.figure('Capacity curve') self.plt = plt # Plot the volume as a function of the level percentage vols = Plot.plot(l, v, 'Capacity') vols.line.set_linestyle('-') vols.line.set_linewidth(2.0) vols.line.set_color((0.0, 0.0, 0.0)) self.l = vols Plot.xlabel(r'$\mathrm{level}$') Plot.ylabel(r'$V \; [\mathrm{m}^3]$') plt.axes.xaxis.label.set_fontsize(20) plt.axes.yaxis.label.set_fontsize(20) Plot.grid(True) # Special percentage formatter for the x axis fmt = '%.0f%%' xticks = mtick.FormatStrFormatter(fmt) plt.axes.xaxis.set_major_formatter(xticks) # Now duplicate the axes ax = Plot.addNewAxes() # Y axis can be placed at right ax.yaxis.tick_right() ax.spines['right'].set_color((0.0, 0.0, 0.0)) ax.spines['left'].set_color('none') ax.yaxis.set_ticks_position('right') ax.yaxis.set_label_position('right') # And X axis can be placed at top ax.xaxis.tick_top() ax.spines['top'].set_color((0.0, 0.0, 1.0)) ax.spines['bottom'].set_color('none') ax.xaxis.set_ticks_position('top') ax.xaxis.set_label_position('top') # Plot the volume as a function of the level z coordinate vols = Plot.plot(z, v, 'level') vols.line.set_linestyle('-') vols.line.set_linewidth(2.0) vols.line.set_color((0.0, 0.0, 1.0)) self.z = vols Plot.xlabel(r'$z \; [\mathrm{m}]$') Plot.ylabel(r'$V \; [\mathrm{m}^3]$') ax.xaxis.label.set_fontsize(20) ax.yaxis.label.set_fontsize(20) ax.xaxis.label.set_color((0.0, 0.0, 1.0)) ax.tick_params(axis='x', colors=(0.0, 0.0, 1.0)) Plot.grid(True) # End plt.update() return False
def setupUi(self): self.form.axId = self.widget(QtGui.QSpinBox, "axesIndex") self.form.new = self.widget(QtGui.QPushButton, "newAxesButton") self.form.remove = self.widget(QtGui.QPushButton, "delAxesButton") self.form.all = self.widget(QtGui.QCheckBox, "allAxes") self.form.xMin = self.widget(QtGui.QSlider, "posXMin") self.form.xMax = self.widget(QtGui.QSlider, "posXMax") self.form.yMin = self.widget(QtGui.QSlider, "posYMin") self.form.yMax = self.widget(QtGui.QSlider, "posYMax") self.form.xAlign = self.widget(QtGui.QComboBox, "xAlign") self.form.yAlign = self.widget(QtGui.QComboBox, "yAlign") self.form.xOffset = self.widget(QtGui.QSpinBox, "xOffset") self.form.yOffset = self.widget(QtGui.QSpinBox, "yOffset") self.form.xAuto = self.widget(QtGui.QCheckBox, "xAuto") self.form.yAuto = self.widget(QtGui.QCheckBox, "yAuto") self.form.xSMin = self.widget(QtGui.QLineEdit, "xMin") self.form.xSMax = self.widget(QtGui.QLineEdit, "xMax") self.form.ySMin = self.widget(QtGui.QLineEdit, "yMin") self.form.ySMax = self.widget(QtGui.QLineEdit, "yMax") self.retranslateUi() # Look for active axes if can axId = 0 plt = Plot.getPlot() if plt: while plt.axes != plt.axesList[axId]: axId = axId + 1 self.form.axId.setValue(axId) self.updateUI() QtCore.QObject.connect(self.form.axId, QtCore.SIGNAL('valueChanged(int)'), self.onAxesId) QtCore.QObject.connect(self.form.new, QtCore.SIGNAL("pressed()"), self.onNew) QtCore.QObject.connect(self.form.remove, QtCore.SIGNAL("pressed()"), self.onRemove) QtCore.QObject.connect(self.form.xMin, QtCore.SIGNAL("valueChanged(int)"), self.onDims) QtCore.QObject.connect(self.form.xMax, QtCore.SIGNAL("valueChanged(int)"), self.onDims) QtCore.QObject.connect(self.form.yMin, QtCore.SIGNAL("valueChanged(int)"), self.onDims) QtCore.QObject.connect(self.form.yMax, QtCore.SIGNAL("valueChanged(int)"), self.onDims) QtCore.QObject.connect(self.form.xAlign, QtCore.SIGNAL("currentIndexChanged(int)"), self.onAlign) QtCore.QObject.connect(self.form.yAlign, QtCore.SIGNAL("currentIndexChanged(int)"), self.onAlign) QtCore.QObject.connect(self.form.xOffset, QtCore.SIGNAL("valueChanged(int)"), self.onOffset) QtCore.QObject.connect(self.form.yOffset, QtCore.SIGNAL("valueChanged(int)"), self.onOffset) QtCore.QObject.connect(self.form.xAuto, QtCore.SIGNAL("stateChanged(int)"), self.onScales) QtCore.QObject.connect(self.form.yAuto, QtCore.SIGNAL("stateChanged(int)"), self.onScales) QtCore.QObject.connect(self.form.xSMin, QtCore.SIGNAL("editingFinished()"), self.onScales) QtCore.QObject.connect(self.form.xSMax, QtCore.SIGNAL("editingFinished()"), self.onScales) QtCore.QObject.connect(self.form.ySMin, QtCore.SIGNAL("editingFinished()"), self.onScales) QtCore.QObject.connect(self.form.ySMax, QtCore.SIGNAL("editingFinished()"), self.onScales) QtCore.QObject.connect( Plot.getMdiArea(), QtCore.SIGNAL("subWindowActivated(QMdiSubWindow*)"), self.onMdiArea) return False