Margins

1,226 views
Skip to first unread message

Leonid Rumatov

unread,
Jun 11, 2013, 6:58:01 AM6/11/13
to pyqt...@googlegroups.com
Hi everybody.
Is there way to set margin for the PlotItem?
I mean, to move left axis left-right and so on.

Luke Campagnola

unread,
Jun 11, 2013, 7:38:39 AM6/11/13
to pyqt...@googlegroups.com
Two ways, depending on your intent:
See PlotItem.setContentsMargins (this is inherited from QGraphicsWidget) and AxisItem.setWidth or setHeight


Luke

Ярослав

unread,
Jun 12, 2013, 2:55:53 AM6/12/13
to Luke Campagnola
Hello, Luke.

Thank you, I'll try this tomorrow.







Luke
-- 
-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]
--- 
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/pyqtgraph/PL8Wu-c_2Is/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
For more options, visit 
https://groups.google.com/groups/opt_out.
 
 




-- 
С уважением,
 Ярослав                          
mailto:dondu...@yandex.ru

Слава

unread,
Jun 12, 2013, 11:11:01 PM6/12/13
to Luke Campagnola
Hello, Luke.

Sorry, this doesn't works.
I mean this length:
(a picture)



Luke

-- 
-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]
--- 
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit 

To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
For more options, visit 
https://groups.google.com/groups/opt_out.
 
 



-- 
Best wishes!
 Слава                            
mailto:dondu...@yandex.ru
int_1.jpg

Luke Campagnola

unread,
Jun 13, 2013, 12:47:47 AM6/13/13
to pyqt...@googlegroups.com
On Wed, Jun 12, 2013 at 11:11 PM, Слава <dondu...@yandex.ru> wrote:
Hello, Luke.

Sorry, this doesn't works.

A bug! Arg. 
It seems to only work when the axis has not been given a label. I'll have this fixed in the next release, but here is a workaround:

plot.getAxis('left').textWidth = 200
p1.getAxis('left').setWidth(200)

Слава

unread,
Jun 13, 2013, 1:09:11 AM6/13/13
to Luke Campagnola
Hello, Luke.

Can I download this next release?
> wrote:
-- 
-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]
--- 
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit 

To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
For more options, visit 

Luke Campagnola

unread,
Jun 13, 2013, 1:17:13 AM6/13/13
to pyqt...@googlegroups.com
On Thu, Jun 13, 2013 at 1:09 AM, Слава <dondu...@yandex.ru> wrote:
Hello, Luke.

Can I download this next release?

It is not packaged yet (and will not be until after I defend my dissertation in August).
Many of the changes that will be in the next release are present in my in-progress branch on launchpad: https://code.launchpad.net/~luke-campagnola/pyqtgraph/inp  but beware that this also has some experimental new features in it that are not well-tested.

Слава

unread,
Jun 14, 2013, 3:05:10 AM6/14/13
to Luke Campagnola
Hello, Luke.

I understand how to move axes.
But I also want to move and scale PlotCurveItem as well.

I guess, the bounds for is depends on painter (param 'p' in 'paint' procedure), but I didn't found where I can manage it.


Thursday, June 13, 2013, 10:47:47 AM, you wrote:

> wrote:
-- 
-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]
--- 
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit 

To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
For more options, visit 

Слава

unread,
Jun 13, 2013, 1:21:49 AM6/13/13
to Luke Campagnola
Hello, Luke.

Thank you, I will see this code.
(I already had download it).

And - I wish you have a successfull defense!
  but beware that this also has some experimental new features in it that are not well-tested.

-- 
-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]
--- 
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit 

To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
For more options, visit 

Luke Campagnola

unread,
Jun 14, 2013, 9:32:31 AM6/14/13
to pyqt...@googlegroups.com
On Fri, Jun 14, 2013 at 3:05 AM, Слава <dondu...@yandex.ru> wrote:
Hello, Luke.

I understand how to move axes.
But I also want to move and scale PlotCurveItem as well.

PlotCurveItem is ultimately a subclass of QGraphicsItem, which provides a huge set of methods to play with (notably, 'scale' and 'translate'). 
If you type help(pg.PlotCurveItem) in an interactive session, you can see the entire set of methods sorted by class. I'm still trying to figure out how to get a list like that automatically generated in the documentation..

Luke

Слава

unread,
Jun 17, 2013, 2:49:22 AM6/17/13
to Luke Campagnola
Hello, Luke.

Yes, I understand.
But, there is a lot of places where I have to apply coefficients, and synchronize it all.
At least 3 places - AxisItem.py, ViewBox.py ('updateMatrix') and code that we create PlotWidget.
That is complex.
(Now I work on it.)
, which provides a huge set of methods to play with (notably, 'scale' and 'translate'). 
-- 
-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]
--- 
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.

To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
For more options, visit 

Luke Campagnola

unread,
Jun 17, 2013, 7:25:04 AM6/17/13
to pyqt...@googlegroups.com
On Mon, Jun 17, 2013 at 2:49 AM, Слава <dondu...@yandex.ru> wrote:
But, there is a lot of places where I have to apply coefficients, and synchronize it all.
At least 3 places - AxisItem.py, ViewBox.py ('updateMatrix') and code that we create PlotWidget.
That is complex.
(Now I work on it.)

It is usually not necessary to to change the scaling of AxisItem--if the data inside the ViewBox is scaled and positioned correctly, the AxisItem should just display the correct range. Likewise, there is usually no need to call ViewBox.updateMatrix. 

If you post some example code, maybe I can understand what you are trying to accomplish and explain how to write it more simply.


Luke
 

Leonid Rumatov

unread,
Jun 17, 2013, 7:48:52 AM6/17/13
to pyqt...@googlegroups.com
I just want to make smaller margins in plot image.
It details:
Lets again see on picture in this message (it's above):
I want to make less size for margins that marked by red arrows.
I can do this by manipulating AxisItem, but this in insufficient. This action gives a bit more horisontal space for PlotCurveItem, so, I must scale PlotCurveItem a little. Also, I have to apply same scale to bottom AxisItem.
It you help me, that will be gracious service from you.


понедельник, 17 июня 2013 г., 17:25:04 UTC+6 пользователь Luke Campagnola написал:

Luke Campagnola

unread,
Jun 17, 2013, 8:03:34 AM6/17/13
to pyqt...@googlegroups.com
On Mon, Jun 17, 2013 at 7:48 AM, Leonid Rumatov <dondu...@yandex.ru> wrote:
I just want to make smaller margins in plot image.
It details:
Lets again see on picture in this message (it's above):
I want to make less size for margins that marked by red arrows.
I can do this by manipulating AxisItem, but this in insufficient. This action gives a bit more horisontal space for PlotCurveItem, so, I must scale PlotCurveItem a little. Also, I have to apply same scale to bottom AxisItem.
It you help me, that will be gracious service from you.

I think I understand--you want the plot to fill the whole horizontal span of the view? You should use ViewBox.setXRange(min, max, padding=0) for that. Let the ViewBox take care of positioning your data on screen; that's what it is for. You should only scale/translate your data (PlotCurveItem) if you want it to appear at a different location relative to the axis values.

It's becoming clear to me that this distinction between data coordinates and display coordinates has confused many people. Perhaps I should write up some new documentation.. 


Luke

Слава

unread,
Jun 17, 2013, 8:27:39 AM6/17/13
to Luke Campagnola
Hello, Luke.

That's good - I apply scale - but insufficient.

Problem 1.

We apply new scale with ViewBox.setXRange(padding=0) and can move axis (left & right) - but this two modification isn't linked. 
I don't want to make margins to strict zero, I just want make it less (half of current size is perfect). 
So, I have to calculate axis translation and padding manually?

Problem 2. 

I have to make some manipulations with 2nd and 3rd viewboxes (p2 and p3) 'geometry' property.
Because the current geometry cut the PlotCurveItem near the left and right borders:
(Curve lines should be continued to marked place, also on right side)


And here I also must to calculate manually.

(At now, sorry, I must go, will answer tommorow.)
-- 
-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]
--- 
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit 

To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
For more options, visit 
int_1.jpg

Слава

unread,
Jun 17, 2013, 8:41:16 AM6/17/13
to Luke Campagnola
Greetings, Luke.

My previous message was too hasty.
I did it!

Well, what I make:
1. to AxisItem - setWidth.

p1.getAxis('left').setWidth(20)
p1.getAxis('right').setWidth(20)
ax3.setWidth(20)

2. to ViewBox.geometry - set new geometry with same value.

def updateViews():
    ## view has resized; update auxiliary views to match
    global p1, p2, p3
    gg1 = p1.vb.sceneBoundingRect()
    gg1.setLeft(20)
    p2.setGeometry(gg1)
    p3.setGeometry(gg1)

3. a-a-a-and - setXRange, as you said, with 'padding' param:
p1.vb.setXRange(1, 5, padding=0)

This don't requres calculating.

Thank you a lot.

But, if some new questions appears, I will send it here.



Monday, June 17, 2013, 6:03:34 PM, you wrote:

-- 
-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]
--- 
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit 

To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
For more options, visit 

Luke Campagnola

unread,
Jun 17, 2013, 9:37:11 AM6/17/13
to pyqt...@googlegroups.com
On Mon, Jun 17, 2013 at 8:41 AM, Слава <dondu...@yandex.ru> wrote:
Well, what I make:
1. to AxisItem - setWidth.

p1.getAxis('left').setWidth(20)
p1.getAxis('right').setWidth(20)
ax3.setWidth(20)

2. to ViewBox.geometry - set new geometry with same value.

def updateViews():
    ## view has resized; update auxiliary views to match
    global p1, p2, p3
    gg1 = p1.vb.sceneBoundingRect()
    gg1.setLeft(20)
    p2.setGeometry(gg1)
    p3.setGeometry(gg1)

This doesn't work correctly for me--the left edges of p2 and p3 do not match p1. 
Can you attach the complete example you are working on so I can see what is different?

Thanks!
Luke

Слава

unread,
Jun 17, 2013, 10:56:34 PM6/17/13
to Luke Campagnola
Hello, Luke.

There is one pixel mistake - I think, I can remove it. 
Here is modified code and screenshot.

# -*- coding: utf-8 -*-
"""
Demonstrates a way to put multiple axes around a single plot. 

(This will eventually become a built-in feature of PlotItem)

"""
#import initExample ## Add path to library (just for examples; you do not need this)

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
from pyqtgraph_margins import *

pg.mkQApp()

pw = pg.PlotWidget()
pw.show()
pw.setWindowTitle('pyqtgraph example: MultiplePlotAxes')
p1 = pw.plotItem
p1.setLabels(left='axis 1')
gg = p1.vb.sceneBoundingRect()
gg.setLeft(20)
p1.vb.setGeometry(gg)
p1.vb.resize(gg.width(), gg.height())

## create a new ViewBox, link the right axis to its coordinate system
p2 = pg.ViewBox()
p1.showAxis('right')
p1.scene().addItem(p2)
p1.getAxis('right').linkToView(p2)
p2.setXLink(p1)
p1.getAxis('right').setLabel('axis2', color='#0000ff')
p1.showGrid(True, True)
#p1.setContentsMargins(-10, 0,-9,0)
p1.vb.setXRange(1, 5, padding=0)

p1.getAxis('left').setWidth(20)
p1.getAxis('right').setWidth(20)

## create third ViewBox. 
## this time we need to create a new axis as well.
p3 = pg.ViewBox()
ax3 = pg.AxisItem('right')
p1.layout.addItem(ax3, 2, 3)
p1.scene().addItem(p3)
ax3.linkToView(p3)
p3.setXLink(p1)
ax3.setZValue(-10000)
ax3.setLabel('axis 3', color='#ff0000')
ax3.setWidth(20)

## Handle view resizing 

def updateViews():
    ## view has resized; update auxiliary views to match
    global p1, p2, p3
    gg1 = p1.vb.sceneBoundingRect()
    gg1.setLeft(20)
    p2.setGeometry(gg1)
    p3.setGeometry(gg1)
    
    ## need to re-update linked axes since this was called
    ## incorrectly while views had different shapes.
    ## (probably this should be handled in ViewBox.resizeEvent)
    p2.linkedViewChanged(p1.vb, p2.XAxis)
    p3.linkedViewChanged(p1.vb, p3.XAxis)

updateViews()
p1.vb.sigResized.connect(updateViews)


curve = pg.PlotDataItem([1,2,4,8,16,32])
p1.addItem(curve)
#p1.plot([1,2,4,8,16,32])
p2.addItem(pg.PlotCurveItem([10,20,40,80,40,20], pen='b'))
p3.addItem(pg.PlotCurveItem([3200,1600,800,400,200,100], pen='r'))

#g = p1.vb.geometry()
#g.setLeft(0)
#p1.vb.setGeometry(g)
set_margins(pw, [32, 20, 3200] )

## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

Here is screenshot:


You can see one-pixel off the border of the red line, left side.
> wrote:
-- 
-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]
--- 
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit 

To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
For more options, visit 
int_1.jpg

Luke Campagnola

unread,
Jun 18, 2013, 12:05:42 PM6/18/13
to pyqt...@googlegroups.com
On Mon, Jun 17, 2013 at 10:56 PM, Слава <dondu...@yandex.ru> wrote:
Hello, Luke.

There is one pixel mistake - I think, I can remove it. 
Here is modified code and screenshot.

I don't have your set_margins module, but If I comment out that line and run the code, I see a large offset ( between the plots and the viewbox, whereas the original MultiplePlotAxes.py looks correct, even after changing the width of the axes. I have a suspicion there may be some differences in our Qt versions that are causing this (and this would explain why it has been so difficult for you to describe the problem to me). Can you tell me the output of pg.systemInfo() on your machine? 

I noticed you are calling p1.vb.setGeometry in a few instances. This should have no effect since the ViewBox is managed by a layout (whereas the second and third viewboxes are not), but again the behavior may be different on your system if our versions are very different..


Luke

Слава

unread,
Jun 18, 2013, 11:29:55 PM6/18/13
to Luke Campagnola
Hello, Luke.

1. 'set_margins' - yes, it doesn't matter, you can comment it.
2. large offset? It's a surprise, I have the small one - you can see on screenshot.
3. My Qt info:
('Qt version:', '4.8.4')
('SIP version:', '4.14.2')
('PyQt version:', '4.9.6')

4. Thank for information about geometry. I try different things, and doensn't understand exactly what each parameter mean.
> wrote:
-- 
-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]
--- 
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit 

To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
For more options, visit 
Reply all
Reply to author
Forward
0 new messages