Obtain lists of plot marker and line styles in Octave - plot

Is there a way to programmatically obtain the list of marker and line styles available for plotting in Octave?
Ideally, I would do something like
mslist = whatever_function_for_marker_styles;
lslist = whatever_function_for_line_styles;
for i = 1:np
plot(x, y(i,:), 'marker', mslist(i), 'linestyle', lslist(i))
endfor
Notes:
I would add some mod functions to cycle across the lists.
I know the size of both lists may not be the same, so they may shift from one another upon cycling.

The easiest way would be to get the symbols from the manual and put them in a cell array:
mslist = {'+', 'o', '*', '.', 'x', 's', 'd', '^', 'v', '>', '<', 'p', 'h'};
lslist = {'-', '--', ':', '-.'};
You can loop over them with a standard for-loop and access them by index using curly brackets, e.g. lslist{i}. The symbols are in Section 15.2.1 of the manual (https://octave.org/doc/v6.1.0/Two_002dDimensional-Plots.html#Two_002dDimensional-Plots). An ordinary vector would work for mslist instead of a cell array as all the symbols are single characters, but not for lslist where some of them are two characters long.

I agree with Howard that doing it 'entirely' programmatically is probably overkill.
However, if you do want to do that, my bet would be to parse the 'help' output for the 'plot' command, which is guaranteed to mention these points, and has a reasonable guarantee that it will remain in the same format even if more markers are added in the future etc.
I won't parse the whole thing, but if you were to do this, you'd probably start like this:
plotdoc = help('plot');
[plotdoc_head , plotdoc_rest] = deal( strsplit( plotdoc , ' linestyle' ){:} );
[plotdoc_lines , plotdoc_rest] = deal( strsplit( plotdoc_rest, ' marker' ){:} );
[plotdoc_markers, plotdoc_rest] = deal( strsplit( plotdoc_rest, ' color' ){:} );
[plotdoc_colors , plotdoc_rest] = deal( strsplit( plotdoc_rest, '";displayname;"' ){:} );
or something along those lines, and then use regexp or strfind / strtoken / strplit creatively to obtain the necessary tokens in each category.

Related

How to assert on a number which is comma separated in cypress

While writing tests on an application I have came across a problem.
I need to fetch a number inside a span from the DOM and then assert if the number is between a specific range.
I can do it by using
cy.get('#my_selector').invoke('text').should('be.gt',lower_bound).and('be.lt',upper_bound)
But the issue is the number is comma separated like 5,000. and I'm getting an error as "expected '5,000' to be a number or a date"
Is there any simple short way to convert it into pure numeric
You can use the javascript replace method to remove the comma and then add a + to convert it into a number, like:
cy.get('#my_selector')
.invoke('text')
.then((num) => {
cy.wrap(+num.replace(/,/g, ''))
.should('be.gt', lower_bound)
.and('be.lt', upper_bound)
})
You can use string.replaceAll() to remove the "," then parseInt()
cy.get('#my_selector')
.invoke('text')
.then(str => parseInt(str.replaceAll(',', '')))
.should('be.within', lower_bound, upper_bound)

Why are some strings in quotes but others aren't when creating a .YAML file from R?

I'm trying to create the following .YAML file:
summary:
title: "Table tabs"
link: ~
blocks: []
nested: nav-pills
nested_names: yes
(note there are no quotes around the tilde, square brackets or yes).
I write the code to create it in R:
tabs <- list(
summary =
list(
title = "Table tabs",
link = "~",
blocks = "[]",
nested = "nav-pills",
nested_names = "yes"
)
)
write(yaml::as.yaml(tabs), file = "myfile.yaml"
But when I write it out to .YAML, it looks like this:
summary:
title: Table tabs
link: '~'
blocks: '[]'
nested: nav-pills
nested_names: 'yes'
i.e. There are quotations around the tilde, square brackets and yes.
Why does this happen, and what can I do to prevent it?
The information is already provided in stackoverflow:
I try to point you through the given answers:
More general considerations using quotes in yaml are discussed sufficiently in the question "YAML: Do I need quotes for strings in YAML?"
Here the difference of ' and "in yaml is discussed:
"What is the difference between a single quote and double quote in Yaml header for r Markdown?"
Specifically the tilde sign is discussed here:
"What is the purpose of tilde character ~ in YAML?"
To summarise,
The tilde is one of the ways the null value can be written. Most
parsers also accept an empty value for null, and of course null, Null
and NULL
Based on the answer from TarJae, the solution is as follows:
tabs <- list(
summary =
list(
title = "Table tabs",
link = NULL,
blocks = list(),
nested = "nav-pills",
nested_names = TRUE
)
)

Update dictionary key inside list using map function -Python

I have a dictionary of phone numbers where number is Key and country is value. I want to update the key and add country code based on value country. I tried to use the map function for this:
print('**Exmaple: Update phone book to add Country code using map function** ')
user=[{'952-201-3787':'US'},{'952-201-5984':'US'},{'9871299':'BD'},{'01632 960513':'UK'}]
#A function that takes a dictionary as arg, not list. List is the outer part
def add_Country_Code(aDict):
for k,v in aDict.items():
if(v == 'US'):
aDict[( '1+'+k)]=aDict.pop(k)
if(v == 'UK'):
aDict[( '044+'+k)]=aDict.pop(k)
if (v == 'BD'):
aDict[('001+'+k)] =aDict.pop(k)
return aDict
new_user=list(map(add_Country_Code,user))
print(new_user)
This works partially when I run, output below :
[{'1+952-201-3787': 'US'}, {'1+1+1+952-201-5984': 'US'}, {'001+9871299': 'BD'}, {'044+01632 960513': 'UK'}]
Notice the 2nd US number has 2 additional 1s'. What is causing that?How to fix? Thanks a lot.
Issue
You are mutating a dict while iterating it. Don't do this. The Pythonic convention would be:
Make a new_dict = {}
While iterating the input a_dict, assign new items to new_dict.
Return the new_dict
IOW, create new things, rather than change old things - likely the source of your woes.
Some notes
Use lowercase with underscores when defining variable names (see PEP 8).
Lookup values rather than change the input dict, e.g. a_dict[k] vs. a_dict.pop(k)
Indent the correct number of spaces (see PEP 8)

How to match space in MarkLogic using CTS functions?

I need to search those elements who have space " " in their attributes.
For example:
<unit href="http:xxxx/unit/2 ">
Suppose above code have space in the last for href attribute.
I have done this using FLOWER query. But I need this to be done using CTS functions. Please suggest.
For FLOWER query I have tried this:
let $x := (
for $d in doc()
order by $d//id
return
for $attribute in data($d//#href)
return
if (fn:contains($attribute," ")) then
<td>{(concat( "id = " , $d//id) ,", data =", $attribute)}</td>
else ()
)
return <tr>{$x}</tr>
This is working fine.
For CTS I have tried
let $query :=
cts:element-attribute-value-query(xs:QName("methodology"),
xs:QName("href"),
xs:string(" "),
"wildcarded")
let $search := cts:search(doc(), $query)
return fn:count($search)
Your query is looking for " " to be the entirety of the value of the attribute. If you want to look for attributes that contain a space, then you need to use wildcards. However, since there is no indexing of whitespace except for exact value queries (which are by definition not wildcarded), you are not going to get a lot of index support for that query, so you'll need to run this as a filtered search (which you have in your code above) with a lot of false positives.
You may be better off creating a string range index on the attribute and doing value-match on that.

Find word (not containing substrings) in comma separated string

I'm using a linq query where i do something liike this:
viewModel.REGISTRATIONGRPS = (From a In db.TABLEA
Select New SubViewModel With {
.SOMEVALUE1 = a.SOMEVALUE1,
...
...
.SOMEVALUE2 = If(commaseparatedstring.Contains(a.SOMEVALUE1), True, False)
}).ToList()
Now my Problem is that this does'n search for words but for substrings so for example:
commaseparatedstring = "EWM,KI,KP"
SOMEVALUE1 = "EW"
It returns true because it's contained in EWM?
What i would need is to find words (not containing substrings) in the comma separated string!
Option 1: Regular Expressions
Regex.IsMatch(commaseparatedstring, #"\b" + Regex.Escape(a.SOMEVALUE1) + #"\b")
The \b parts are called "word boundaries" and tell the regex engine that you are looking for a "full word". The Regex.Escape(...) ensures that the regex engine will not try to interpret "special characters" in the text you are trying to match. For example, if you are trying to match "one+two", the Regex.Escape method will return "one\+two".
Also, be sure to include the System.Text.RegularExpressions at the top of your code file.
See Regex.IsMatch Method (String, String) on MSDN for more information.
Option 2: Split the String
You could also try splitting the string which would be a bit simpler, though probably less efficient.
commaseparatedstring.Split(new Char[] { ',' }).Contains( a.SOMEVALUE1 )
what about:
- separating the commaseparatedstring by comma
- calling equals() on each substring instead of contains() on whole thing?
.SOMEVALUE2 = If(commaseparatedstring.Split(',').Contains(a.SOMEVALUE1), True, False)

Resources