I'm having a problem with my text and radial stimuli in Psychopy.It seems like all of my text stim are shifted to the left. Despite the fact that the ($8, 0%) is given the same x coordinates as the radial stimuli they are consistently to the left of the radial stimuli and I'm not sure why
Lot_a_win=visual.RadialStim(win=win,units="pix",name='Lot', color=col_code,opacity=1,
angularCycles = 0, radialCycles = 0, radialPhase = 0.5, colorSpace = 'rgb',
ori= -90.0,pos=(lot_pos,0), size=(300,300),visibleWedge=(0.0, shade))
Lot_a_lose= visual.RadialStim( win=win, name='rad2', color=col_code,opacity=0.5,
angularCycles = 0, radialCycles = 0, radialPhase = 0.5, colorSpace = 'rgb',
ori= 45.0, pos=(lot_pos,0), size=(300,300))
Lot_a_lose.draw()
Lot_a_win.draw()
SureMoney=visual.TextStim(win=win,text="$ %s"%(sure_m),pos=sure_pos,bold=True,units='pix')
SureMoney.draw()
Lot_per=visual.TextStim(win=win,text="%s %%"%(lot_p),pos=(lot_pos,-50),bold=True,units='pix')
Lot_Money=visual.TextStim(win=win,text="$ %s"%(lot_m),pos=(lot_pos,50),bold=True,units='pix')
Lot_per.draw()
Lot_Money.draw()
My guess is that you've got pyglet 1.4 installed and the text positioning system has changed. PsychoPy will support the changed system as best we can but, in the meantime I'd suggest you downgrade pyglet to 1.3.x
Related
I don't seem to be able to figure out why pymupdf tools for placing objects on pdf documents has the origin set at a seemingly random location. Notice that (0,0,100,100), which is x0 y1 x2 y2 (where y starts from top) starts from the middle of the page for the y axis. x axis appears fine. I cannot seem to find anything in the documentation about this.
import fitz
doc = fitz.open('PDF4.pdf')
page = doc.load_page(0)
box = page.new_shape()
box.draw_rect(fitz.Rect(0, 0, 100, 100)) # x0, y0-2505, x2, y2
box.finish(color=(0, 0, 0), fill=(0, 0, 1),fill_opacity = 0.25)
box.commit()
doc.save("x.pdf")
This appears to solve this and reset the origin. This seems to have changed to snake casing from camel casing recently, making current solutions to this online fail.
if not page.is_wrapped:
page.wrap_contents()
I'm showing some strange discrepancies between my declared camera position (scene.camera.pos), and the actual camera position. I can't believe this feature is just broken, am I missing something here?
Here's the code, and the output shown below
GlowScript 3.1 VPython
cube = box(pos=vector(0, 0, 0), size=vector(1,1,1), color=color.red, texture=textures.rough)
scene.lights = [distant_light(direction=vector(0.4226, 0, -0.9063),color=color.gray(0.7)),distant_light(direction=vector(0.4226, 0, -0.9063),color=color.gray(0.7))]
scene.background = color.gray(0.8)
scene.camera.pos = vector(3,3,-3)
scene.camera.axis = cube.pos - scene.camera.pos
#scene.forward=cube.pos
#scene.camera.center=cube.pos
#scene.camera.fov = (pi/180)*10
#scene.camera.axis = vector(0, 0, 0)
#scene.up = vector(0,1,0)
while True:
rate(0.5)
scene.append_to_title(scene.camera.pos)
#scene.camera.rotate(angle=0.05, axis=vec(0,0,1), origin=vec(0,10,0))
#scene.capture("woah")
I think I see the problem. There is a conflict between you manipulating the camera and the default scene.autoscale = True. If you set scene.autoscale = False before manipulating the camera, I think you'll find that the program behaves as expected. At the very least, this implies a need for the camera documentation to point out this conflict.
Finally checked back in on this and it's working properly now.
I am plotting a 3d_image using GLSurfacePlotItem.
My Z-axis Data lies between 0 - 255
gl.GLSurfacePlotItem(x=x[:, 0], y=y[0, :], shader='heightColor', computeNormals=False, smooth=False)
Following is the ColorMap:
p4.shader()['colorMap'] = np.array([0.45, 0, 0.1, 0.005, 0.5, 2, 0, 0.05, 0.2])
I do get some color shade in the output image but would like to know how can i enable multiple colors in the same
Thanks
I came across the following answer on google groups , which I am copying across here, as it is the first item I have come across on the web giving details of how the colormap works on pyqtgraph for 3d plots
copied across from google groups
Hi,
Yeah, the GL stuff doesn't use the same colour maps as the 2D images. I can't see any documentation on the shaders (http://www.pyqtgraph.org/documentation/3dgraphics/glmeshitem.html) that are used to colour the surface. Looking at the code under shaders.py does help though. For the "heightColor" shader, the 9 numbers in the array that are used (as in the Surface Plot example) are variables used in a formula to compute the RGB colour.
From comment in code:
## colors fragments by z-value.
## This is useful for coloring surface plots by height.
## This shader uses a uniform called "colorMap" to determine how to map the colors:
## red = pow(z * colorMap[0] + colorMap[1], colorMap[2])
## green = pow(z * colorMap[3] + colorMap[4], colorMap[5])
## blue = pow(z * colorMap[6] + colorMap[7], colorMap[8])
## (set the values like this: shader['uniformMap'] = array([...])
I assume the output RGB values are expressed as a range from 0 to 1. So to tweak the example to work with ranges from say zmin to zmax, I think something like:
p4.shader()['colorMap'] = np.array([0.2*(zmax - zmin), 2 - zmin, 0.5, 0.2*(zmax - zmin), 1 - zmin, 1, 0.2*(zmax - zmin), 0 - zmin, 2])
Patrick
In pyqtgraph you can scatterplot each item for itself or a whole bunch of them as bulk (using spots). working with large datasets i prefer the last method since the figure stays light and is movable without lagging all over the screen.
my problem
some of my symbols i need an angle... that isn't that much of a problem, however if i add them separately to the plot it results in a laggy figure. so my problem is that i am currently unable to find a suitable way to subclass the whole thing and implement a small method for the keyword argument "rotation"/"angle". has anyone finished this task already or has someone an idea?
thank you very much in advance!
After another look today I finally found that it was way too simple: Just rotating my symbol before adding it to the ScatterPlotItem did the trick. For the sake of documentation and maybe some other struggling programmers, a snippet:
import numpy as np
import pyqtgraph as pg
# define a symbol bowtie style
_mos = np.asarray([
[0.5, 0.25],
[0.5, -0.25],
[-0.5, 0.25],
[-0.5, -0.25],
[0.5, 0.25]
])
my_symbol = pg.arrayToQPath(_mos[:, 0], _mos[:, 1], connect='all')
# define color and stuff for your items
exit_item = pg.ScatterPlotItem(
size=20,
pen=pg.mkPen(128, 128, 128, 255),
brush=pg.mkBrush(255, 255, 255, 255),
)
# calculate angle between two sets of points
angle = np.arctan2(np.asarray(y1-y0), np.asarray(x1-x0)) * 180/np.pi
# rotate symbol with that angle
tr = QTransform()
angle_rot = tr.rotate(angle)
my_rotated_symbol = angle_rot.map(my_symbol)
# may be a whole list of spots with different angles and positions
exit_spots = []
exit_spots.append({
'pos': (0, 0),
'symbol': my_rotated_symbol
})
# add the spots to the item
exit_item.addPoints(exit_spots)
# create a plot and add the content
win = pg.GraphicsWindow()
plot = win.addPlot()
plot.addItem(exit_item)
I want to reserve some space on the screen for my Gtk application written in Python. I've wrote this function:
import xcb, xcb.xproto
import struct
def reserve_space(xid, data):
connection = xcb.connect()
atom_cookie = connection.core.InternAtom(True, len("_NET_WM_STRUT_PARTIAL"),
"_NET_WM_STRUT_PARTIAL")
type_cookie = connection.core.InternAtom(True, len("CARDINAL"), "CARDINAL")
atom = atom_cookie.reply().atom
atom_type = type_cookie.reply().atom
data_p = struct.pack("I I I I I I I I I I I I", *data)
strat_cookie = connection.core.ChangeProperty(xcb.xproto.PropMode.Replace, xid,
atom, xcb.xproto.Atom.CARDINAL, 32, len(data_p), data_p)
connection.flush()
It's call looks like this:
utils.reserve_space(xid, [0, 60, 0, 0, 0, 0, 24, 767, 0, 0, 0, 0])
Unfortunately, it doesn't work. Where is an error in my code?
UPD:
Here is my xprop output. My WM is Compiz.
I have uploaded a gist that demonstrates how to specify a strut across the top of the current monitor for what might be a task-bar. It may help explain some of this.
The gist of my gist is below:
window = gtk.Window()
window.show_all()
topw = window.get_toplevel().window
topw.property_change("_NET_WM_STRUT","CARDINAL",32,gtk.gdk.PROP_MODE_REPLACE,
[0, 0, bar_size, 0])
topw.property_change("_NET_WM_STRUT_PARTIAL","CARDINAL",32,gtk.gdk.PROP_MODE_REPLACE,
[0, 0, bar_size, 0, 0, 0, 0, 0, x, x+width, 0, 0])
I found the strut arguments confusing at first, so here is an explanation that I hope is clearer:
we set _NET_WM_STRUT, the older mechanism as well as _NET_WM_STRUT_PARTIAL but window managers ignore the former if they support the latter. The numbers in the array are as follows:
0, 0, bar_size, 0 are the number of pixels to reserve along each edge of the screen given in the order left, right, top, bottom. Here the size of the bar is reserved at the top of the screen and the other edges are left alone.
_NET_WM_STRUT_PARTIAL also supplies a further four pairs, each being a start and end position for the strut (they don't need to occupy the entire edge).
In the example, we set the top start to the current monitor's x co-ordinate and the top-end to the same value plus that monitor's width. The net result is that space is reserved only on the current monitor.
Note that co-ordinates are specified relative to the screen (i.e. all monitors together).
(see the referenced gist for the full context)
Changing to using ChangePropertyChecked(), and then checking the result gives a BadLength exception.
I think the bug here is that the ChangeProperty() parameter data_len is the number of elements of the size given by format , not the number of bytes, in the property data data.
Slightly modified code which works for me:
def reserve_space(xid, data):
connection = xcb.connect()
atom_cookie = connection.core.InternAtom(False, len("_NET_WM_STRUT_PARTIAL"),
"_NET_WM_STRUT_PARTIAL")
atom = atom_cookie.reply().atom
data_p = struct.pack("12I", *data)
strat_cookie = connection.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, xid,
atom, xcb.xproto.Atom.CARDINAL, 32, len(data_p)/4, data_p)
strat_cookie.check()
connection.flush()