[Matplotlib-users] Plot rescales the first few clicks - how to disallow overlapping ?

2009-08-23 Thread Ala Al-Shaibani
Hello everyone,

I was playing around with matplotlib, created a plot that allows users to add 
nodes (axis is set off as it's going to be used for graph data structuer 
purposes, hence don't want the y-x axis, is there another way to hide them as 
well?).

Basically the program below allows person press the 'n' button, and then can 
click on any point on the plot and a small circular marker will appear.

I have two questions:

1) You will notice that during the first 2 marker inputs, the plot rescales it 
self. I don't really know why that's happening, any idea?
2) Is it possible to disallow users of creating to marker points ontop of each 
other, so that no markers will overlap (even if the edges)?

Thank you.




 Code
from pylab import *
from matplotlib.widgets import *

fig = plt.figure()
ax = fig.add_subplot(111)
fig.set_facecolor('w')
ax.set_axis_off()
ax.set_title('Test 1')
cid = None
def onClick(event):
docstring for onClick
ax.plot([event.xdata], [event.ydata], 'bo', picker=5, markersize=15)
draw()
fig.canvas.mpl_disconnect(cid)
def onPick(event):
docstring for onPick
artist = event.artist
artist.set_color('r')
draw()
def add_node(event):
docstring for press
if event.key==n:
global cid
fig.canvas.mpl_disconnect(cid)
cid = fig.canvas.mpl_connect('button_press_event',onClick)
fig.canvas.mpl_connect('key_press_event', add_node)
fig.canvas.mpl_connect('pick_event',onPick)

plt.show()


  --
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] regarding networkx, matplotlib and pyqt

2009-07-20 Thread Ala Al-Shaibani
Hello everyone.

A users on the networkx mailing list posted this example which is a 
modification of the matplotlib-pyqt4 implementation which plots a networkx 
graph.

The problem I am facing with it is that two plot windows open instead of one, 
one is empty and the other contains the graph.

I can't really put my finger as to why two windows open rather than just one 
pyqt window with the plot. Any suggestions would be appreciated.

Screenshot of the two plot windows:
http://img259.imageshack.us/img259/8722/picture1ahr.jpg

Code:
#!/usr/bin/env python

# embedding_in_qt4.py --- Simple Qt4 application embedding matplotlib canvases
#
# Copyright (C) 2005 Florent Rougon
#  2006 Darren Dale
#
# This file is an example program for matplotlib. It may be used and
# modified with no restriction; raw copies as well as modified versions
# may be distributed without limitation.

import sys, os, random
from PyQt4 import QtGui, QtCore

from numpy import arange, sin, pi
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
import networkx as nx

progname = os.path.basename(sys.argv[0])
progversion = 0.1


class MyMplCanvas(FigureCanvas):
Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.).
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
# We want the axes cleared every time plot() is called
self.axes.hold(False)

self.compute_initial_figure()

#
FigureCanvas.__init__(self, fig)
self.setParent(parent)

FigureCanvas.setSizePolicy(self,
  QtGui.QSizePolicy.Expanding,
  QtGui.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)

def compute_initial_figure(self):
pass


class MyStaticMplCanvas(MyMplCanvas):
Simple canvas with a sine plot.
def compute_initial_figure(self):
G=nx.path_graph(10)
pos=nx.spring_layout(G)
nx.draw(G,pos,ax=self.axes)


class ApplicationWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setWindowTitle(application main window)

self.file_menu = QtGui.QMenu('File', self)
self.file_menu.addAction('Quit', self.fileQuit,
QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
self.menuBar().addMenu(self.file_menu)

self.help_menu = QtGui.QMenu('Help', self)
self.menuBar().addSeparator()
self.help_menu.addAction('About', self.about)

self.menuBar().addMenu(self.help_menu)


self.main_widget = QtGui.QWidget(self)

l = QtGui.QVBoxLayout(self.main_widget)
sc = MyStaticMplCanvas(self.main_widget, width=5, height=4, dpi=100)
l.addWidget(sc)

self.main_widget.setFocus()
self.setCentralWidget(self.main_widget)

self.statusBar().showMessage(All hail matplotlib!, 2000)

def fileQuit(self):
self.close()

def closeEvent(self, ce):
self.fileQuit()

def about(self):
QtGui.QMessageBox.about(self, About %s % progname,
u%(prog)s version %(version)s
Copyright \N{COPYRIGHT SIGN} 2005 Florent Rougon, 2006 Darren Dale

This program is a simple example of a Qt4 application embedding matplotlib
canvases.

It may be used and modified with no restriction; raw copies as well as
modified versions may be distributed without limitation.
% {prog: progname, version: progversion})


qApp = QtGui.QApplication(sys.argv)

aw = ApplicationWindow()
aw.setWindowTitle(%s % progname)
aw.show()
sys.exit(qApp.exec_())
#qApp.exec_()


  --
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users