Slider bar in altair interactive plot with wrong front and initial placement - dataframe

I have this interactive plot with a slider bar over the 'Time' field. My problems are:
The font is different from the other texts in the plot (both with Chrome and Edge). I looked at the doc but I could not find a way to change it. Is it possible?
I cannot set the init attribute of the slider properly. Following the example doc I try to set init={'Time': 3} (I need it to be at the end), but I get the following error
selector = alt.selection_single(
File "C:\Users\sparisi\Anaconda3\lib\site-packages\altair\vegalite\v5\api.py", line 395, in selection_single
return selection(type="point", **kwargs)
File "C:\Users\sparisi\Anaconda3\lib\site-packages\altair\vegalite\v5\api.py", line 365, in selection
return parameter(select=select, **param_kwds)
File "C:\Users\sparisi\Anaconda3\lib\site-packages\altair\vegalite\v5\api.py", line 319, in parameter
parameter.param = core.SelectionParameter(
File "C:\Users\sparisi\Anaconda3\lib\site-packages\altair\vegalite\v5\schema\core.py", line 14283, in __init__
super(SelectionParameter, self).__init__(name=name, select=select, bind=bind, value=value,
File "C:\Users\sparisi\Anaconda3\lib\site-packages\altair\utils\schemapi.py", line 177, in __init__
self.to_dict(validate=True)
File "C:\Users\sparisi\Anaconda3\lib\site-packages\altair\utils\schemapi.py", line 340, in to_dict
raise SchemaValidationError(self, err)
altair.utils.schemapi.SchemaValidationError: Invalid specification
altair.vegalite.v5.schema.core.SelectionParameter->0, validating 'type'
3 is not of type 'array'

Since you are a bit ahead of the curve (since you are on vegalite V5 already), you can use the upcoming parameter for interactivity in Altair. See here for some examples https://christopherdavisuci.github.io/UCI-Math-10/param.html
Especially the transform-filter section is relevant for you.
Here you see the init is replaced with a value parameter.
Regarding the init error you observe. I cannot reproduce this using the example you refer to (see this colab notebook), so I suspect something else is wrong. If you prepare a minimum reproducible example I can have a look again.
Regarding the font of the sliders. There is no known syntax in altair for doing this, but if it is important for you, you can overrule the css. See this SO answer for an example https://stackoverflow.com/a/62104504/2459096

Related

Incorrect context when trying to reload text

in order to develop my script in an external IDE, I'm trying to automatically reload a text in blender when it is modified from outside of Blender. I think I've got the idea of how it works, but there must be one tiny detail that completely blocks me from achieving my goal.
My script is the following:
import bpy
import sys
ctx = bpy.context.copy()
for area in ctx['screen'].areas:
if area.type == 'TEXT_EDITOR':
textEditor = area
for text in bpy.data.texts:
if text.name == 'main.py':
textEditor.spaces[0].text = text
bpy.ops.text.reload()
Output:
>>> exec(bpy.data.texts['reload.py'].as_string())
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
File "<string>", line 13, in <module>
File "/Applications/Blender.app/Contents/Resources/3.3/scripts/modules/bpy/ops.py", line 113, in __call__
ret = _op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.text.reload.poll() failed, context is incorrect
I cannot get what part of the context is correct. I found no solution on the Internet, even the doc recommends reading the source code to understand what might be the cause of this error, but I couldn't find it anyway in the source code.
Can someone tell me what I am missing here please?

How to have multi-page table row cells converted properly using rst2pdf Shpinx?

I have a table of which one-row cell has so much data that it could span multiple pages in the finally-generated PDF file. rst2pdf ungracefully fails when I feed it my file, with the following output:
[ERROR] pdfbuilder.py:161 Failed to build doc
Traceback (most recent call last):
File "/home/pwng/.local/lib/python3.9/site-packages/rst2pdf/pdfbuilder.py", line 158, in write
docwriter.write(doctree, destination)
File "/usr/lib/python3/dist-packages/docutils/writers/__init__.py", line 78, in write
self.translate()
File "/home/pwng/.local/lib/python3.9/site-packages/rst2pdf/pdfbuilder.py", line 697, in translate
createpdf.RstToPdf(
File "/home/pwng/.local/lib/python3.9/site-packages/rst2pdf/createpdf.py", line 689, in createPdf
pdfdoc.multiBuild(elements)
File "/usr/lib/python3/dist-packages/reportlab/platypus/doctemplate.py", line 1167, in multiBuild
self.build(tempStory, **buildKwds)
File "/usr/lib/python3/dist-packages/reportlab/platypus/doctemplate.py", line 1080, in build
self.handle_flowable(flowables)
File "/home/pwng/.local/lib/python3.9/site-packages/rst2pdf/createpdf.py", line 859, in handle_flowable
self.handle_frameEnd()
File "/usr/lib/python3/dist-packages/reportlab/platypus/doctemplate.py", line 726, in handle_frameEnd
self.handle_pageEnd()
File "/usr/lib/python3/dist-packages/reportlab/platypus/doctemplate.py", line 668, in handle_pageEnd
raise LayoutError(ident)
reportlab.platypus.doctemplate.LayoutError: More than 10 pages generated without content - halting layout. Likely that a flowable is too large for any frame.
FAILED
build succeeded.
and make latexpdf produce undesirable output depicted in the following screenshot.
Is there a way to remedy this problem using either latexpdf or rst2pdf? Ideally, I would like a solution that works for both spaced text (i.e. space-separated words) and consecutive, wrapped non-separated text.
This isn't the answer you want, but rst2pdf won't split the cell across pages, so if it doesn't fit onto the page, it won't be able to generate the document. The project (I'm a maintainer) is open to patches, in case you end up fixing it yourself. I'm not aware of a workaround, other than reformatting the content to be more printable.

GNU Radio OOT block: AttributeError: module 'twoTypes' has no attribute 'passthrough_cc'

What I'm trying to do:
I am trying to write an OOT block for GNU radio that accept complex or byte values and just pass through. (My final target is obviously do some processing of the incoming stream, but it had so many errors, I had to go back to the basics)
The error:
I receive this error at runtime
traceback (most recent call last):
File "/home/maisun/Desktop/asdf.py", line 193, in <module>
main()
File "/home/maisun/Desktop/asdf.py", line 171, in main
tb = top_block_cls()
File "/home/maisun/Desktop/asdf.py", line 82, in __init__
self.twoTypes_passthrough_0 = twoTypes.passthrough_cc(0)
AttributeError: module 'twoTypes' has no attribute 'passthrough_cc'
what I've tried:
I have looked into the source of GR itself and tried to correct my yaml files, my header files. To the best of my knowledge, I have defined 'passthrough_cc' in the twoTypes.h header file as,
typedef passthrough<std::uint8_t> passthrough_bb;
typedef passthrough<gr_complex> passthrough_cc;
Obviosly i'm still doing something wrong here.
my questions:
I have 2 questions.
First, how can I correct the CPP code and the python module? so that I can call passthrough_cc without errors.
second, I am more comfortable in C language. So sometimes GR codes are very confusing to me. GR wiki has some nice guides available. But does anyone know if there is any guide/blog post that kind of discusses the workflow of GR? For example, when I trace my codes, I start from main() and follow the flow. with GR I always get lost.
full code:
https://github.com/maisunmonowar/gr-twoTypes

Error when using mathtext.fontset = 'custom' in stylelib

I encounter a strange behavior using matplotlib when I try define a custom math font (with usetex=false):
mpl.__version__ = '2.0.2' with python 2.7
I define a stylesheet (i.e. *.mplstyle file in stylelib folder) in which I write
mathtext.fontset = 'custom'
mathtext.rm = 'Avenir Next'
mathtext.it = 'Avenir Next:italic'
mathtext.bf = 'Avenir Next:bold'
mathtext.fallback_to_cm : True
If I try to make a plot with that style I get the error:
Bad key "mathtext.rm = 'Avenir Next" on line 49 in
/Users/gp/.matplotlib/stylelib/simple.mplstyle.
You probably need to get an updated matplotlibrc file from
http://github.com/matplotlib/matplotlib/blob/master/matplotlibrc.template
or from the matplotlib source distribution
UserWarning: In /Users/gp/.matplotlib/stylelib/simple.mplstyle: Illegal line #48
"mathtext.fontset = 'custom'
"
in file "/Users/gp/.matplotlib/stylelib/simple.mplstyle"
And also similar errors about mathtext.it and mathtext.bf.
If I instead comment these lines out and just write into the py document that I use to generate the plot (after loading the style with the now commented lines about mathtext) the following lines than everything works flawless (w/o error and with the expected behavior).
mpl.rcParams['mathtext.fontset'] = 'custom'
mpl.rcParams['mathtext.rm'] = 'Avenir Next'
mpl.rcParams['mathtext.it'] = 'Avenir Next:italic'
mpl.rcParams['mathtext.bf'] = 'Avenir Next:bold'
I am puzzled because the lines of my stylesheet are as described in the matplotlib documentary. Can somebody make anything of it?
Georg
edit: typos
After sitting over it for some days I posted the question just to realize directly afterwards that the syntax in the style file is wrong at several places.
The single quotation marks don't belong there. Also the =must be replaced by colons :.
Then it works!

PsychoPy - Workaround for (still ongoing) pyglet memory leak affecting text components displayed at frame-level

I too have run across the infamous pyglet memory leak, that occurs when one needs to update text components at the frame level (with a text variable typically computed in a separate code component, also at frame level).
The leak/bug crashes a running script with an error message of the sort:
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.83.04-py2.7.egg\psychopy\visual\window.py", line 541, in flip
thisStim.draw()
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.83.04-py2.7.egg\psychopy\visual\text.py", line 603, in draw
self._pygletTextObj.draw()
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\pyglet\font\__init__.py", line 565, in draw
self._layout.draw()
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\pyglet\text\layout.py", line 852, in draw
self.batch.draw()
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\pyglet\graphics\__init__.py", line 544, in draw
func()
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\pyglet\graphics\__init__.py", line 476, in <lambda>
(lambda d, m: lambda: d.draw(m))(domain, mode))
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\pyglet\graphics\vertexdomain.py", line 313, in draw
glDrawArrays(mode, starts[0], sizes[0])
WindowsError: exception: access violation reading 0x00000010
Exception TypeError: "'NoneType' object is not callable" in <bound method Server.__del__ of <pyolib.server.Server object at 0x0EFB3670>> ignored
I know the PsychoPy community has linked this to a memory leak in pyglet that was meant to have been fixed around April 2016 according to this thread. I downloaded the latest version of Pyglet (which is v1.2.4 - released apparently in Sep 2015, so before the supposed fix of the leak) and replaced its contents under c:\Program Files (x86)\PsychoPy2\Lib\site-packages\pyglet\. However, this did not fix my problem.
Unfortunately, my experiment does not make sense if I give up the frame-wise computation that feeds the text component.
An older thread that I found suggested the following workaround: in the code component that computes frame-wise the value of the text variable being displayed, only assign this variable a new value if that new value actually differs from the previous value. However, even after changing my code component this way, the pyglet error still pops up.
Assuming the bug was fixed in Pyglet, is it not v1.2.4 that reflects this fix, and should it not be updated by overwriting the contents of c:\Program Files (x86)\PsychoPy2\Lib\site-packages\pyglet\ (maintaining the original folder structure)?
Assuming the bug was in fact NOT fixed in Pyglet, can anyone suggested a different workaround that I can try to make my PsychoPy expt not crash?
Many thanks indeed for your help.
(Apologies for the double post both here and on the psychopy group; will update both threads as soon as there is a response on the other, to avoid people wasting time with double answers).
One workaround is to use TextBox instead of TextStim. To do that, one first defines a stimulus object in a code component (under "begin routine"), such as
textbox = visual.TextBox(window=win,
text='Something',
font_size=21,
font_color=[-1,-1,1],
size=(1.9, .3),
pos=(0.0, 0.25),
grid_horz_justification='center',
units='norm')
then, perhaps under the "every frame" tab, one uses code to customise & call upon the thus-defined textbox, with syntax as found on http://www.psychopy.org/api/visual/textbox.html