You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
(12) |
Sep
(12) |
Oct
(56) |
Nov
(65) |
Dec
(37) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(59) |
Feb
(78) |
Mar
(153) |
Apr
(205) |
May
(184) |
Jun
(123) |
Jul
(171) |
Aug
(156) |
Sep
(190) |
Oct
(120) |
Nov
(154) |
Dec
(223) |
| 2005 |
Jan
(184) |
Feb
(267) |
Mar
(214) |
Apr
(286) |
May
(320) |
Jun
(299) |
Jul
(348) |
Aug
(283) |
Sep
(355) |
Oct
(293) |
Nov
(232) |
Dec
(203) |
| 2006 |
Jan
(352) |
Feb
(358) |
Mar
(403) |
Apr
(313) |
May
(165) |
Jun
(281) |
Jul
(316) |
Aug
(228) |
Sep
(279) |
Oct
(243) |
Nov
(315) |
Dec
(345) |
| 2007 |
Jan
(260) |
Feb
(323) |
Mar
(340) |
Apr
(319) |
May
(290) |
Jun
(296) |
Jul
(221) |
Aug
(292) |
Sep
(242) |
Oct
(248) |
Nov
(242) |
Dec
(332) |
| 2008 |
Jan
(312) |
Feb
(359) |
Mar
(454) |
Apr
(287) |
May
(340) |
Jun
(450) |
Jul
(403) |
Aug
(324) |
Sep
(349) |
Oct
(385) |
Nov
(363) |
Dec
(437) |
| 2009 |
Jan
(500) |
Feb
(301) |
Mar
(409) |
Apr
(486) |
May
(545) |
Jun
(391) |
Jul
(518) |
Aug
(497) |
Sep
(492) |
Oct
(429) |
Nov
(357) |
Dec
(310) |
| 2010 |
Jan
(371) |
Feb
(657) |
Mar
(519) |
Apr
(432) |
May
(312) |
Jun
(416) |
Jul
(477) |
Aug
(386) |
Sep
(419) |
Oct
(435) |
Nov
(320) |
Dec
(202) |
| 2011 |
Jan
(321) |
Feb
(413) |
Mar
(299) |
Apr
(215) |
May
(284) |
Jun
(203) |
Jul
(207) |
Aug
(314) |
Sep
(321) |
Oct
(259) |
Nov
(347) |
Dec
(209) |
| 2012 |
Jan
(322) |
Feb
(414) |
Mar
(377) |
Apr
(179) |
May
(173) |
Jun
(234) |
Jul
(295) |
Aug
(239) |
Sep
(276) |
Oct
(355) |
Nov
(144) |
Dec
(108) |
| 2013 |
Jan
(170) |
Feb
(89) |
Mar
(204) |
Apr
(133) |
May
(142) |
Jun
(89) |
Jul
(160) |
Aug
(180) |
Sep
(69) |
Oct
(136) |
Nov
(83) |
Dec
(32) |
| 2014 |
Jan
(71) |
Feb
(90) |
Mar
(161) |
Apr
(117) |
May
(78) |
Jun
(94) |
Jul
(60) |
Aug
(83) |
Sep
(102) |
Oct
(132) |
Nov
(154) |
Dec
(96) |
| 2015 |
Jan
(45) |
Feb
(138) |
Mar
(176) |
Apr
(132) |
May
(119) |
Jun
(124) |
Jul
(77) |
Aug
(31) |
Sep
(34) |
Oct
(22) |
Nov
(23) |
Dec
(9) |
| 2016 |
Jan
(26) |
Feb
(17) |
Mar
(10) |
Apr
(8) |
May
(4) |
Jun
(8) |
Jul
(6) |
Aug
(5) |
Sep
(9) |
Oct
(4) |
Nov
|
Dec
|
| 2017 |
Jan
(5) |
Feb
(7) |
Mar
(1) |
Apr
(5) |
May
|
Jun
(3) |
Jul
(6) |
Aug
(1) |
Sep
|
Oct
(2) |
Nov
(1) |
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2025 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
|
|
|
|
|
1
(17) |
2
(3) |
3
(2) |
|
4
(11) |
5
(8) |
6
(22) |
7
(16) |
8
(9) |
9
(14) |
10
(1) |
|
11
(8) |
12
(5) |
13
(7) |
14
(10) |
15
(28) |
16
(8) |
17
(20) |
|
18
(6) |
19
(5) |
20
(15) |
21
(8) |
22
(7) |
23
(14) |
24
(10) |
|
25
(6) |
26
(8) |
27
(9) |
28
(11) |
29
(13) |
30
(20) |
|
|
From: Gökhan S. <gok...@gm...> - 2011-09-24 22:45:13
|
Hello,
Please consider my attached examples. hw3.py nicely produces multiple axes
electromagnetic spectrum with solar and terrestrial radiation plotted using
Planck's function. However, the major and minor ticks placements are not
nice in those plots and I have decided to use the new axis_grid1 interface.
In the original hw3.py I do multiple plots of desired unit (e.g. wavelength
to wavenumber etc...) I am quite sure that the units shown in the hw3.py are
correctly converted. Now I am planning to produce these conversions with mpl
transformations. Then test1-hw3.py comes into view once again.
Can someone possibly (JJ) give little hint here as to converting from
wavelength to wavenumber using Affine2D and correctly see the ticks located
as the main x-axis.
I do lots of extra lines to get this one working properly in the hw3.py as
shown below:
# multi x-axes
# first wavenumber in cm^-1
parx = ax1.twiny()
parx.axis["top"].set_visible(False)
offset = 0, -60
new_axisline = parx.get_grid_helper().new_fixed_axis
parx.axis["bottom"] = new_axisline(loc="bottom", axes=parx, offset=offset)
parx.axis["bottom"].label.set_visible(True)
parx.axis["bottom"].label.set_text(u"Wavenumber, cm⁻¹")
parx.axis["bottom"].label.set_fontsize(16)
line1, = parx.plot(1/(wavelength[1:]*100), np.ones(len(wavelength[1:])))
line1.set_visible(0)
parx.set_xlim(xmin=1e10,xmax=1/1e6)
parx.set_xscale('log')
Thanks.
--
Gökhan
|
|
From: Vineet J. <vin...@gm...> - 2011-09-24 15:58:14
|
HI modified one of the examples and it brings up the chart window with the
custom toolbar. However, nothing happens with the "pickevent"
"""
This demo demonstrates how to embed a matplotlib (mpl) plot
into a PyQt4 GUI application, including:
* Using the navigation toolbar
* Adding data to the plot
* Dynamically modifying the plot's properties
* Processing mpl events
* Saving the plot to a file from a menu
The main goal is to serve as a basis for developing rich PyQt GUI
applications featuring mpl plots (using the mpl OO API).
Eli Bendersky (el...@gm...)
License: this code is in the public domain
Last modified: 19.01.2009
"""
from __future__ import division
import sys, os, random
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import matplotlib
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as
FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as
NavigationToolbar
from matplotlib.figure import Figure
import math
import os
import sys
import matplotlib
from matplotlib import verbose
from matplotlib.backend_bases import cursors
from matplotlib.figure import Figure
try:
from PyQt4 import QtCore, QtGui, Qt
except ImportError:
raise ImportError("Qt4 backend requires that PyQt4 is installed.")
cursord = {
cursors.MOVE : QtCore.Qt.SizeAllCursor,
cursors.HAND : QtCore.Qt.PointingHandCursor,
cursors.POINTER : QtCore.Qt.ArrowCursor,
cursors.SELECT_REGION : QtCore.Qt.CrossCursor,
}
class NavigationToolbarCustom(NavigationToolbar):
def __init__(self, *args, **kwargs):
pixmap = QtGui.QPixmap()
pixmap.load(':/cross.png')
cursors.SELECT_POINT = pixmap
super(NavigationToolbar, self).__init__(*args, **kwargs)
def _init_toolbar(self):
self.basedir = os.path.join(matplotlib.rcParams[ 'datapath'
],'images')
a = self.addAction(self._icon('home.svg'), 'Home', self.home)
a.setToolTip('Reset original view')
a = self.addAction(self._icon('back.svg'), 'Back', self.back)
a.setToolTip('Back to previous view')
a = self.addAction(self._icon('forward.svg'), 'Forward',
self.forward)
a.setToolTip('Forward to next view')
self.addSeparator()
a = self.addAction(self._icon('move.svg'), 'Pan', self.pan)
a.setToolTip('Pan axes with left mouse, zoom with right')
a = self.addAction(self._icon('zoom_to_rect.svg'), 'Zoom',
self.zoom)
a.setToolTip('Zoom to rectangle')
a = self.addAction(self._icon('hand.svg'), 'Select',
self.selectPointMode)
a.setToolTip('Select the nearest data point')
self.addSeparator()
a = self.addAction(self._icon('subplots.png'), 'Subplots',
self.configure_subplots)
a.setToolTip('Configure subplots')
a = self.addAction(self._icon('filesave.svg'), 'Save',
self.save_figure)
a.setToolTip('Save the figure')
self.buttons = {}
# Add the x,y location widget at the right side of the toolbar
# The stretch factor is 1 which means any resizing of the toolbar
# will resize this label instead of the buttons.
if self.coordinates:
self.locLabel = QtGui.QLabel( "", self )
self.locLabel.setAlignment(
QtCore.Qt.AlignRight | QtCore.Qt.AlignTop )
self.locLabel.setSizePolicy(
QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Ignored))
labelAction = self.addWidget(self.locLabel)
labelAction.setVisible(True)
# reference holder for subplots_adjust window
self.adj_window = None
def mouse_move(self, event):
print 'mouse_move', event.button
if not event.inaxes or not self._active:
if self._lastCursor != cursors.POINTER:
self.set_cursor(cursors.POINTER)
self._lastCursor = cursors.POINTER
else:
if self._active=='ZOOM':
if self._lastCursor != cursors.SELECT_REGION:
self.set_cursor(cursors.SELECT_REGION)
self._lastCursor = cursors.SELECT_REGION
if self._xypress:
x, y = event.x, event.y
lastx, lasty, a, ind, lim, trans = self._xypress[0]
self.draw_rubberband(event, x, y, lastx, lasty)
elif (self._active=='PAN' and
self._lastCursor != cursors.MOVE):
self.set_cursor(cursors.MOVE)
self._lastCursor = cursors.MOVE
elif self._active=='SELECT':
if self._lastCursor != cursors.SELECT_POINT:
QtGui.QApplication.restoreOverrideCursor()
QtGui.QApplication.setOverrideCursor(QtGui.QCursor(cursors.SELECT_POINT))
self._lastCursor = cursors.SELECT_POINT
if event.inaxes and event.inaxes.get_navigate():
try: s = event.inaxes.format_coord(event.xdata, event.ydata)
except ValueError: pass
except OverflowError: pass
else:
if len(self.mode):
self.set_message('%s : %s' % (self.mode, s))
else:
self.set_message(s)
else: self.set_message(self.mode)
def selectPointMode(self, *args):
if self._active == 'SELECT':
self._active = None
else:
self._active = 'SELECT'
if self._idPress is not None:
self._idPress = self.canvas.mpl_disconnect(self._idPress)
self.mode = ''
if self._idRelease is not None:
self._idRelease = self.canvas.mpl_disconnect(self._idRelease)
self.mode = ''
if self._active:
self._idRelease = self.canvas.mpl_connect(
'button_press_event', self.selectPoint)
self.mode = 'pixel select mode'
self.canvas.widgetlock(self)
else:
self.canvas.widgetlock.release(self)
self.set_message(self.mode)
def selectPoint(self, event):
if event.inaxes and event.inaxes.get_navigate():
print 'selectPoint: ', 1
self.xdatastart=event.xdata
print 'selectPoint: ', 2
self.ydatastart=event.ydata
self.xstart=event.x
self.ystart=event.y
print 'selectPoint: ', 3
self._banddraw = self.canvas.mpl_connect(
'motion_notify_event',self.drawband)
print 'selectPoint: ', 4
self._idRelease = self.canvas.mpl_disconnect(self._idRelease)
self._idRelease = self.canvas.mpl_connect(
'button_release_event', self.selectSecondPoint)
print 'selectPoint: ', 5
def selectSecondPoint(self, event):
if event.inaxes and event.inaxes.get_navigate():
print 'selectSecondPoint: ', 1
self._banddraw=self.canvas.mpl_disconnect(self._banddraw)
print 'selectSecondPoint: ', 2
self._idRelease = self.canvas.mpl_disconnect(self._idRelease)
print 'selectSecondPoint: ', 3
self._idRelease = self.canvas.mpl_connect(
'button_press_event', self.selectPoint)
self.draw_rubberband(event, 0, 0, 0, 0)
print 'selectSecondPoint: ', 4
self.emit(
QtCore.SIGNAL('pickEvent'),
self.xdatastart,
self.ydatastart,
event.xdata,
event.ydata
)
print 'selectSecondPoint: ', 5
def drawband(self, event):
self.draw_rubberband(event,self.xstart, self.ystart, event.x,
event.y)
def onPick(self, xstart, ystart, xend, yend):
xstart_i, ystart_i = self.getIndices(xstart, ystart)
xend_i, yend_i = self.getIndices(xend, yend)
if xstart_i > xend_i: xstart_i, xend_i = xend_i, xstart_i
if ystart_i > yend_i: ystart_i, yend_i = yend_i, ystart_i
try:
indices = self.indices[ystart_i:yend_i+1, xstart_i:xend_i+1]
print indices
self.emit(QtCore.SIGNAL('pickEvent'), indices.flatten())
except TypeError:
pass
def getIndices(self, xdata, ydata):
xIndex = locateClosest(xdata, self.xPixelLocs)
yIndex = locateClosest(ydata, self.yPixelLocs)
return xIndex, yIndex
def locateClosest(point, points):
compare = numpy.abs(points-point)
return numpy.nonzero(numpy.ravel(compare==compare.min()))[0]
class AppForm(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.setWindowTitle('Demo: PyQt with matplotlib')
self.create_menu()
self.create_main_frame()
self.create_status_bar()
self.textbox.setText('1 2 3 4')
self.on_draw()
def save_plot(self):
file_choices = "PNG (*.png)|*.png"
path = unicode(QFileDialog.getSaveFileName(self,
'Save file', '',
file_choices))
if path:
self.canvas.print_figure(path, dpi=self.dpi)
self.statusBar().showMessage('Saved to %s' % path, 2000)
def on_about(self):
msg = """ A demo of using PyQt with matplotlib:
* Use the matplotlib navigation bar
* Add values to the text box and press Enter (or click "Draw")
* Show or hide the grid
* Drag the slider to modify the width of the bars
* Save the plot to a file using the File menu
* Click on a bar to receive an informative message
"""
QMessageBox.about(self, "About the demo", msg.strip())
def on_pick(self, event):
# The event received here is of the type
# matplotlib.backend_bases.PickEvent
#
# It carries lots of information, of which we're using
# only a small amount here.
#
box_points = event.artist.get_bbox().get_points()
msg = "You've clicked on a bar with coords:\n %s" % box_points
QMessageBox.information(self, "Click!", msg)
def on_draw(self):
""" Redraws the figure
"""
str = unicode(self.textbox.text())
self.data = map(int, str.split())
x = range(len(self.data))
# clear the axes and redraw the plot anew
#
self.axes.clear()
self.axes.grid(self.grid_cb.isChecked())
self.axes.bar(
left=x,
height=self.data,
width=self.slider.value() / 100.0,
align='center',
alpha=0.44,
picker=5)
self.canvas.draw()
def create_main_frame(self):
self.main_frame = QWidget()
# Create the mpl Figure and FigCanvas objects.
# 5x4 inches, 100 dots-per-inch
#
self.dpi = 100
self.fig = Figure((5.0, 4.0), dpi=self.dpi)
self.canvas = FigureCanvas(self.fig)
self.canvas.setParent(self.main_frame)
# Since we have only one plot, we can use add_axes
# instead of add_subplot, but then the subplot
# configuration tool in the navigation toolbar wouldn't
# work.
#
self.axes = self.fig.add_subplot(111)
# Bind the 'pick' event for clicking on one of the bars
#
self.canvas.mpl_connect('pick_event', self.on_pick)
self.canvas.mpl_connect('pickevent', self.onPick)
# Create the navigation toolbar, tied to the canvas
#
self.mpl_toolbar = NavigationToolbarCustom(self.canvas,
self.main_frame)
# Other GUI controls
#
self.textbox = QLineEdit()
self.textbox.setMinimumWidth(200)
self.connect(self.textbox, SIGNAL('editingFinished ()'),
self.on_draw)
self.draw_button = QPushButton("&Draw")
self.connect(self.draw_button, SIGNAL('clicked()'), self.on_draw)
self.grid_cb = QCheckBox("Show &Grid")
self.grid_cb.setChecked(False)
self.connect(self.grid_cb, SIGNAL('stateChanged(int)'),
self.on_draw)
slider_label = QLabel('Bar width (%):')
self.slider = QSlider(QtCore.Qt.Horizontal)
self.slider.setRange(1, 100)
self.slider.setValue(20)
self.slider.setTracking(True)
self.slider.setTickPosition(QSlider.TicksBothSides)
self.connect(self.slider, SIGNAL('valueChanged(int)'), self.on_draw)
#
# Layout with box sizers
#
hbox = QHBoxLayout()
for w in [ self.textbox, self.draw_button, self.grid_cb,
slider_label, self.slider]:
hbox.addWidget(w)
hbox.setAlignment(w, QtCore.Qt.AlignVCenter)
vbox = QVBoxLayout()
vbox.addWidget(self.canvas)
vbox.addWidget(self.mpl_toolbar)
vbox.addLayout(hbox)
self.main_frame.setLayout(vbox)
self.setCentralWidget(self.main_frame)
def create_status_bar(self):
self.status_text = QLabel("This is a demo")
self.statusBar().addWidget(self.status_text, 1)
def create_menu(self):
self.file_menu = self.menuBar().addMenu("&File")
load_file_action = self.create_action("&Save plot",
shortcut="Ctrl+S", slot=self.save_plot,
tip="Save the plot")
quit_action = self.create_action("&Quit", slot=self.close,
shortcut="Ctrl+Q", tip="Close the application")
self.add_actions(self.file_menu,
(load_file_action, None, quit_action))
self.help_menu = self.menuBar().addMenu("&Help")
about_action = self.create_action("&About",
shortcut='F1', slot=self.on_about,
tip='About the demo')
self.add_actions(self.help_menu, (about_action,))
def add_actions(self, target, actions):
for action in actions:
if action is None:
target.addSeparator()
else:
target.addAction(action)
def create_action( self, text, slot=None, shortcut=None,
icon=None, tip=None, checkable=False,
signal="triggered()"):
action = QAction(text, self)
if icon is not None:
action.setIcon(QIcon(":/%s.png" % icon))
if shortcut is not None:
action.setShortcut(shortcut)
if tip is not None:
action.setToolTip(tip)
action.setStatusTip(tip)
if slot is not None:
self.connect(action, SIGNAL(signal), slot)
if checkable:
action.setCheckable(True)
return action
def main():
app = QApplication(sys.argv)
form = AppForm()
form.show()
app.exec_()
if __name__ == "__main__":
main()
|
|
From: Vineet J. <vin...@gm...> - 2011-09-24 13:59:33
|
Hi, I'm looking at Darren's example of extending matplotlib's toolbar from 2008. Any ideal where I can find the base class MplToolbar? Can some just help me with figuring out which example in matplotlib 1.01 I should start with to use his cutom ToolBar? http://www.mailinglistarchive.com/html/mat...@li.../2008-11/msg00107.html Here is his custom toolbar: (copied from above link) -------------------------------------------------------------------------------------------------------------------------------------------------------- I have a Toolbar subclass that adds a button to graphically select a subset from the data, its sort of similar to the zoom tool only it doesnt zoom. This is specific to Qt4, but maybe you will find it useful. Toolbar._init_toolbar adds a "Select" action, which is wired so that one corner of a rectangle is defined by the mouse press, the opposite by the mouse release: class Toolbar(MplToolbar): def __init__(self, *args, **kwargs): pixmap = QtGui.QPixmap() pixmap.load(':/cross.png') mplCursors.SELECT_POINT = pixmap super(Toolbar, self).__init__(*args, **kwargs) def _init_toolbar(self): self.basedir = os.path.join(mpl.rcParams[ 'datapath' ],'images') a = self.addAction(self._icon('home.svg'), 'Home', self.home) a.setToolTip('Reset original view') a = self.addAction(self._icon('back.svg'), 'Back', self.back) a.setToolTip('Back to previous view') a = self.addAction(self._icon('forward.svg'), 'Forward', self.forward) a.setToolTip('Forward to next view') self.addSeparator() a = self.addAction(self._icon('move.svg'), 'Pan', self.pan) a.setToolTip('Pan axes with left mouse, zoom with right') a = self.addAction(self._icon('zoom_to_rect.svg'), 'Zoom', self.zoom) a.setToolTip('Zoom to rectangle') a = self.addAction(QtGui.QIcon(':/crosshairs.svg'), 'Select', self.selectPointMode) a.setToolTip('Select the nearest data point') self.addSeparator() a = self.addAction(self._icon('subplots.png'), 'Subplots', self.configure_subplots) a.setToolTip('Configure subplots') a = self.addAction(self._icon('filesave.svg'), 'Save', self.save_figure) a.setToolTip('Save the figure') self.buttons = {} # Add the x,y location widget at the right side of the toolbar # The stretch factor is 1 which means any resizing of the toolbar # will resize this label instead of the buttons. if self.coordinates: self.locLabel = QtGui.QLabel( "", self ) self.locLabel.setAlignment( QtCore.Qt.AlignRight | QtCore.Qt.AlignTop ) self.locLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Ignored)) labelAction = self.addWidget(self.locLabel) labelAction.setVisible(True) # reference holder for subplots_adjust window self.adj_window = None def mouse_move(self, event): #print 'mouse_move', event.button if not event.inaxes or not self._active: if self._lastCursor != mplCursors.POINTER: self.set_cursor(mplCursors.POINTER) self._lastCursor = mplCursors.POINTER else: if self._active=='ZOOM': if self._lastCursor != mplCursors.SELECT_REGION: self.set_cursor(mplCursors.SELECT_REGION) self._lastCursor = mplCursors.SELECT_REGION if self._xypress: x, y = event.x, event.y lastx, lasty, a, ind, lim, trans = self._xypress[0] self.draw_rubberband(event, x, y, lastx, lasty) elif (self._active=='PAN' and self._lastCursor != mplCursors.MOVE): self.set_cursor(mplCursors.MOVE) self._lastCursor = mplCursors.MOVE elif self._active=='SELECT': if self._lastCursor != mplCursors.SELECT_POINT: QtGui.QApplication.restoreOverrideCursor() QtGui.QApplication.setOverrideCursor( QtGui.QCursor(mplCursors.SELECT_POINT)) self._lastCursor = mplCursors.SELECT_POINT if event.inaxes and event.inaxes.get_navigate(): try: s = event.inaxes.format_coord(event.xdata, event.ydata) except ValueError: pass except OverflowError: pass else: if len(self.mode): self.set_message('%s : %s' % (self.mode, s)) else: self.set_message(s) else: self.set_message(self.mode) def selectPointMode(self, *args): if self._active == 'SELECT': self._active = None else: self._active = 'SELECT' if self._idPress is not None: self._idPress = self.canvas.mpl_disconnect(self._idPress) self.mode = '' if self._idRelease is not None: self._idRelease = self.canvas.mpl_disconnect(self._idRelease) self.mode = '' if self._active: self._idRelease = self.canvas.mpl_connect( 'button_press_event', self.selectPoint) self.mode = 'pixel select mode' self.canvas.widgetlock(self) else: self.canvas.widgetlock.release(self) self.set_message(self.mode) def selectPoint(self, event): if event.inaxes and event.inaxes.get_navigate(): self.xdatastart=event.xdata self.ydatastart=event.ydata self.xstart=event.x self.ystart=event.y self._banddraw = self.canvas.mpl_connect( 'motion_notify_event',self.drawband) self._idRelease = self.canvas.mpl_disconnect(self._idRelease) self._idRelease = self.canvas.mpl_connect( 'button_release_event', self.selectSecondPoint) def selectSecondPoint(self, event): if event.inaxes and event.inaxes.get_navigate(): self._banddraw=self.canvas.mpl_disconnect(self._banddraw) self._idRelease = self.canvas.mpl_disconnect(self._idRelease) self._idRelease = self.canvas.mpl_connect( 'button_press_event', self.selectPoint) self.draw_rubberband(event, 0, 0, 0, 0) self.emit( QtCore.SIGNAL('pickEvent'), self.xdatastart, self.ydatastart, event.xdata, event.ydata ) def drawband(self, event): self.draw_rubberband(event,self.xstart, self.ystart, event.x, event.y) The mouse release calls selectSecondPoint, which emits a signal containing the x and y start and end data. That gets routed to the onPick method on my Qt4Canvas instance: def onPick(self, xstart, ystart, xend, yend): xstart_i, ystart_i = self.getIndices(xstart, ystart) xend_i, yend_i = self.getIndices(xend, yend) if xstart_i > xend_i: xstart_i, xend_i = xend_i, xstart_i if ystart_i > yend_i: ystart_i, yend_i = yend_i, ystart_i try: indices = self.indices[ystart_i:yend_i+1, xstart_i:xend_i+1] self.emit(QtCore.SIGNAL('pickEvent'), indices.flatten()) except TypeError: pass which determines the indices of my data that are contained within the region defined by the user: def getIndices(self, xdata, ydata): xIndex = locateClosest(xdata, self.xPixelLocs) yIndex = locateClosest(ydata, self.yPixelLocs) return xIndex, yIndex def locateClosest(point, points): compare = numpy.abs(points-point) return numpy.nonzero(numpy.ravel(compare==compare.min()))[0] |
|
From: Andreas M. <and...@gm...> - 2011-09-24 11:00:29
|
Paul Ivanov wrote: > On Fri, Sep 23, 2011 at 2:08 PM, Andreas Matthias > <and...@gm...> wrote: >> In the following example the coordinates of the mouse >> cursor displayed in the pylab window belong to the >> second y-axis. But I would prefer to have the coordinates >> of the first y-axis to be displayed. Is this possible? > > yes it is. > >> import pylab as mpl >> >> mpl.plot([1,3,2]) >> mpl.twinx() >> mpl.plot([400,50,100]) >> mpl.show() > > # get the current figure > f = mpl.gcf() > > # Hide the "background" for the first axes, otherwise it will block > the second one when we swap > f.axes[0].set_frame_on(False) > > # Swap the axes > f.axes.reverse() > > # Turn on the "background" for the *new* first axes (the one that was > created second) > f.axes[0].set_frame_on(False) Hmm. I do not get a reversed list of axes. This is the output of the example code below: [<matplotlib.axes.AxesSubplot object at 0x8d8fb4c>, <matplotlib.axes.Axes object at 0x8f633ec>] [<matplotlib.axes.AxesSubplot object at 0x8d8fb4c>, <matplotlib.axes.Axes object at 0x8f633ec>] BTW, what's matplotlib.axes.AxesSubplot? I couldn't find this class. Ciao Andreas import pylab as mpl mpl.plot([1,3,2]) mpl.twinx() mpl.plot([400,50,100]) f = mpl.gcf() print f.axes f.axes[0].set_frame_on(False) f.axes.reverse() f.axes[0].set_frame_on(True) print f.axes mpl.show() |
|
From: Paul I. <piv...@gm...> - 2011-09-24 08:47:18
|
Hi Eric,
On Wed, Sep 21, 2011 at 9:11 AM, Eric O LEBIGOT (EOL)
<Eri...@no...> wrote:
> With the Mac OS X backend (at least…), error messages are repeatedly printed
> when the mouse leaves the axes rectangle:
>
> File
> "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py",
> line 420, in draw_rubberband
> self.canvas.set_rubberband(x0, y0, x1, y1)
> TypeError: integer argument expected, got float
>
> This problem is annoying because the error messages clutter the terminal,
> and useful printed information leaves the screen. :)
This problem was fixed by 2c924046 (Jim Radford 2011-03-08 15:07:23 -0800 459)
and now reads:
self.canvas.set_rubberband(int(x0), int(y0), int(x1), int(y1))
Please update either that line alone, or checkout the latest
matplotlib sources from GitHub.
best,
--
Paul Ivanov
314 address only used for lists, off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7
|
|
From: Eric O L. (EOL) <Eri...@no...> - 2011-09-24 08:27:06
|
[Reposting this because it has been "pending" for 2 days]
With the Mac OS X backend (at least…), when zooming (with the rubberband
rectangle), error messages are repeatedly printed when the mouse leaves
(goes outside) the axes rectangle:
Traceback (most recent call last):
File
"/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backend_bases.py",
line 1625, in motion_notify_event
self.callbacks.process(s, event)
File
"/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/cbook.py",
line 265, in process
proxy(*args, **kwargs)
File
"/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/cbook.py",
line 191, in __call__
return mtd(*args, **kwargs)
File
"/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backend_bases.py",
line 2573, in drag_zoom
self.draw_rubberband(event, x, y, lastx, lasty)
File
"/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py",
line 420, in draw_rubberband
self.canvas.set_rubberband(x0, y0, x1, y1)
TypeError: integer argument expected, got float
This problem is annoying because the error messages clutter the terminal,
and useful printed information leaves the screen. :)
Configuration: Mac OS X 10.7, latest MacPort's Python and modules,
Matplotlib 1.0.1 with Mac OS X backend.
--
View this message in context: http://old.nabble.com/Bug-error-when-zooming-tp32503898p32503898.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
|
|
From: Paul I. <piv...@gm...> - 2011-09-24 06:12:40
|
Hi Andreas, On Fri, Sep 23, 2011 at 2:08 PM, Andreas Matthias <and...@gm...> wrote: > In the following example the coordinates of the mouse > cursor displayed in the pylab window belong to the > second y-axis. But I would prefer to have the coordinates > of the first y-axis to be displayed. Is this possible? yes it is. > import pylab as mpl > > mpl.plot([1,3,2]) > mpl.twinx() > mpl.plot([400,50,100]) > mpl.show() # get the current figure f = mpl.gcf() # Hide the "background" for the first axes, otherwise it will block the second one when we swap f.axes[0].set_frame_on(False) # Swap the axes f.axes.reverse() # Turn on the "background" for the *new* first axes (the one that was created second) f.axes[0].set_frame_on(False) you can also achieve the same effect by changing the zorder of axes - provided that you remember to have turn the frame on for the one that is the furthest back, and turn it off for all others lying on top of it. You can see what happens if you don't do this by omitting the calls to set_frame_on, and then verifying that the second line does not show up (because the original axes' frame patch is blocking it. best, -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 |
|
From: Gökhan S. <gok...@gm...> - 2011-09-24 06:08:09
|
One more update, before heading to the bed. I have managed to adjust my ticks to get what I was asking originally. See the code at http://pastebin.com/XjkDZ486 1-) ax1.yaxis.set_minor_locator(ticker.LogLocator(subs=np.arange(2.0, 10.0)) ) with this line I can get the desired number of minor ticks at the correct positions 2-) #ax1.xaxis.set_ticks(10.**np.arange(np.log10(xmin),np.log10(xmax)+1,1)) this line puts major at every decade but minors aren't printed correctly due to striding at major ticks. 3-) To get this one working I needed to modify the code within the ticker.LogLocator() particularly the two lines starting at https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/ticker.py#L1311 decades = np.arange(math.floor(vmin), math.ceil(vmax)+stride, stride) edited to decades = np.arange(math.floor(vmin), math.ceil(vmax)+1, 1) previously I was getting a major tick at every other decade. With this change I get a major tick at every decade plus the minor ticks look nicer. So my opinion is this stride should be parameter to the LogLocator(), so based on what people wants to plot it can be easily adjusted. Any comments/other solutions? Thanks. * * On Fri, Sep 23, 2011 at 10:47 PM, Gökhan Sever <gok...@gm...>wrote: > OK, > > This fixes the minor locations on y-axis > > ax1.yaxis.set_minor_locator(ticker.LogLocator(subs=np.arange(2.0, 10.0))) > > Independent of the data-range. It seems like ticker.LogLocator is trying to > adjust the minor locs internally. > > > On Fri, Sep 23, 2011 at 7:18 PM, Gökhan Sever <gok...@gm...>wrote: > >> Hi, >> >> Another question is, what sets the tick-location on a log scaled axis? >> (that 10^-5, 10^-3, 10^-1, 10^1) It seems as if the range is greater than >> certain value ticks are located this way. Also in a similar way, the >> location of minor ticks are decided. (If the range is big, no minor ticks, >> if the range is not too big, put 4 minor ticks --which is >> very inconvenient to eye, if range is small then nicely locate 9 minor >> ticks.) >> >> Hah, the next probably will be manually forcing the _ticks or ticklocator >> functions. >> >> Anyone else experiencing similar behavior in mpl? >> >> On Fri, Sep 23, 2011 at 1:07 PM, Gökhan Sever <gok...@gm...>wrote: >> >>> Hello, >>> >>> Considering this example plot: >>> http://imageshack.us/photo/my-images/27/imagefki.png/ >>> >>> How can I get the minor ticks showing correctly? (ie., 9 minor ticks per >>> decade likewise for the x-axis) >>> >>> For some reason >>> >>> axis.set_minor_locator(LogLocator(numdecs=9) is not producing the desired >>> output. >>> >>> Any hints? >>> >>> Thanks. >>> >>> -- >>> Gökhan >>> >> >> >> >> -- >> Gökhan >> > > > > -- > Gökhan > -- Gökhan |
|
From: Gökhan S. <gok...@gm...> - 2011-09-24 04:47:48
|
OK, This fixes the minor locations on y-axis ax1.yaxis.set_minor_locator(ticker.LogLocator(subs=np.arange(2.0, 10.0))) Independent of the data-range. It seems like ticker.LogLocator is trying to adjust the minor locs internally. On Fri, Sep 23, 2011 at 7:18 PM, Gökhan Sever <gok...@gm...> wrote: > Hi, > > Another question is, what sets the tick-location on a log scaled axis? > (that 10^-5, 10^-3, 10^-1, 10^1) It seems as if the range is greater than > certain value ticks are located this way. Also in a similar way, the > location of minor ticks are decided. (If the range is big, no minor ticks, > if the range is not too big, put 4 minor ticks --which is > very inconvenient to eye, if range is small then nicely locate 9 minor > ticks.) > > Hah, the next probably will be manually forcing the _ticks or ticklocator > functions. > > Anyone else experiencing similar behavior in mpl? > > On Fri, Sep 23, 2011 at 1:07 PM, Gökhan Sever <gok...@gm...>wrote: > >> Hello, >> >> Considering this example plot: >> http://imageshack.us/photo/my-images/27/imagefki.png/ >> >> How can I get the minor ticks showing correctly? (ie., 9 minor ticks per >> decade likewise for the x-axis) >> >> For some reason >> >> axis.set_minor_locator(LogLocator(numdecs=9) is not producing the desired >> output. >> >> Any hints? >> >> Thanks. >> >> -- >> Gökhan >> > > > > -- > Gökhan > -- Gökhan |
|
From: Gökhan S. <gok...@gm...> - 2011-09-24 01:18:46
|
Hi, Another question is, what sets the tick-location on a log scaled axis? (that 10^-5, 10^-3, 10^-1, 10^1) It seems as if the range is greater than certain value ticks are located this way. Also in a similar way, the location of minor ticks are decided. (If the range is big, no minor ticks, if the range is not too big, put 4 minor ticks --which is very inconvenient to eye, if range is small then nicely locate 9 minor ticks.) Hah, the next probably will be manually forcing the _ticks or ticklocator functions. Anyone else experiencing similar behavior in mpl? On Fri, Sep 23, 2011 at 1:07 PM, Gökhan Sever <gok...@gm...> wrote: > Hello, > > Considering this example plot: > http://imageshack.us/photo/my-images/27/imagefki.png/ > > How can I get the minor ticks showing correctly? (ie., 9 minor ticks per > decade likewise for the x-axis) > > For some reason > > axis.set_minor_locator(LogLocator(numdecs=9) is not producing the desired > output. > > Any hints? > > Thanks. > > -- > Gökhan > -- Gökhan |