Restrict plot range

744 views
Skip to first unread message

Mike

unread,
Jan 28, 2014, 12:53:30 PM1/28/14
to pyqt...@googlegroups.com
Hi,

Is it possible to restrict plot area to say only positive x and y values when dragging curve with a mouse? For example when running SimplePlot.py example it is possible to drag curve up until it is completely hidden and negative y values appear on the y-axis.

Regards,
Mikhail

P.S. Luke, thank you for the very nice library!

Luke Campagnola

unread,
Jan 30, 2014, 11:08:45 AM1/30/14
to pyqt...@googlegroups.com
On Tue, Jan 28, 2014 at 12:53 PM, Mike <ter...@gmail.com> wrote:
Is it possible to restrict plot area to say only positive x and y values when dragging curve with a mouse? For example when running SimplePlot.py example it is possible to drag curve up until it is completely hidden and negative y values appear on the y-axis.

I started working on this a while ago.. just pushed up the current state to a topic branch here:
https://github.com/lcampagn/pyqtgraph/tree/viewbox_limits

The basic features are there, but it still needs more testing and some user interface tweaks. See ViewBox.setLimits for an explanation of the feature and examples/ViewLimits.py


Luke

Mike

unread,
Jan 30, 2014, 11:47:58 PM1/30/14
to pyqt...@googlegroups.com
Hi,
 
Great, but IMHO the interface is a little bit confusing. The example in examples/ViewLimits.py actually shows that:

plt.centralWidget.vb.setLimits(xRange=[-100, 100], minRange=[0.1, None], maxRange=[50, None])

xRange=[-100, 100] implies that minimum X value is -100 but minRange=[0.1, None] says that minimum X value is 0.1. When I ran the example and played with the mouse I was able to get to the point where X-axis showed negative values. This is a case where too much flexibility actually makes it harder to comprehend and use. IMHO.

BTW may be I misunderstood something in the terminology. If I change the above line in the example to

plt.centralWidget.vb.setLimits(minRange=[0.1, None], maxRange=[50, None])

then using my mouse I can make X axis to show all negative values.

So what would be the right way to restrict the plot view to the positive quadrant (mouse interaction included)?


Luke Campagnola

unread,
Jan 31, 2014, 7:59:49 AM1/31/14
to pyqt...@googlegroups.com
The terminology is definitely confusing (I haven't worked out anything better yet). The xRange and yRange options limit *where* the view can see along either axis. So xRange=[-100, 100] will prevent panning outside that range on the x axis. In contrast, the minRange and maxRange options limit the scaling of the axes. Using minRange=[0.1, None] means that you cannot zoom in such that the distance from the left side of the view to the right is less than 0.1.
 

Mike

unread,
Jan 31, 2014, 10:46:34 AM1/31/14
to pyqt...@googlegroups.com

Thanks for the explanation. I see the difference now. The confusing part is using 'Range' in both names. The more traditional name for xRange would be xLimits IMHO.

Also it looks like xRange and xMin, xMax are the same thing but there is no check for consistency. For example the following is accepted without error or warning but the xRange is just ignored:

plt.centralWidget.vb.setLimits(xRange=[-100, 100], xMax=1, minRange=[0.1, None], maxRange=[50, None])

When I put to make xMin > xMax like there:

plt.centralWidget.vb.setLimits(xRange=[-100, 100], xMin=10, xMax=1, minRange=[0.1, None], maxRange=[50, None])

the maxRange doesn't work - the X axis stays still [10,1].

I think that some consistency checks would be very useful otherwise the debugging could be very frustrating.




Luke Campagnola

unread,
Jan 31, 2014, 1:10:12 PM1/31/14
to pyqt...@googlegroups.com
Thanks for the suggestions! I have pushed up some changes:
 - redundant arguments are now removed
 - argument names are (hopefully) less ambiguous
 - docstring for setLimits is improved
 - fixed some mouse interaction bugs
 
Let me know how these work for you.

Mike

unread,
Jan 31, 2014, 9:16:22 PM1/31/14
to pyqt...@googlegroups.com
 - redundant arguments are now removed
 - argument names are (hopefully) less ambiguous
 - docstring for setLimits is improved
 - fixed some mouse interaction bugs
 
Let me know how these work for you.

Tank you very much, it works great now! 

Mike

unread,
Feb 2, 2014, 7:11:34 PM2/2/14
to pyqt...@googlegroups.com

Let me know how these work for you.

One more suggestion - expose it in say PlotWidget.
Otherwise plt.centralWidget.vb.setLimits looks too internal.

Luke Campagnola

unread,
Feb 4, 2014, 8:34:04 PM2/4/14
to pyqt...@googlegroups.com
Done!
I have merged setLimits in to the develop branch; this will appear in the 0.9.9 release.
 

Mike

unread,
Feb 4, 2014, 11:16:28 PM2/4/14
to pyqt...@googlegroups.com

Thank you!
Reply all
Reply to author
Forward
0 new messages