rgraph is not formulating y axis correctly - rgraph

I have a large grouped chart and the y axis will not formulate properly. I have tried getting rid of zeros, and double checking for syntax typos and cannot seem to figure it out. Basically the y-axis ticks are 0 0 1 1 thats it???
<script>
window.onload = function ()
{
var data = [ ['18','47','11'] , ['10','4','1'] , ['0','0','1'] , ['0','2','0'] , ['8','9','0'] , ['6','6','0'] , ['5','3','1'] , ['2','7','0'] , ['9','5','1'] , ['5','6','0'] , ['6','5','0'] , ['4','5','0'] , ['3','2','2'] , ['3','2','0'] , ['0','1','0'] , ['1','0','0'] ] ;
var bar = new RGraph.Bar('cvs', data)
.Set('labels', ['JH', '166', 'JC', 'DR', 'KL', '206', '499', '181', '127', '01', '211', 'RK', '111', '46', '485', '65'])
.Set('colors', ['Gradient(#99f:#27afe9:#058DC7:#058DC7)', 'Gradient(#94f776:#50B332:#B1E59F)', 'Gradient(#fe783e:#EC561B:#F59F7D)'])
.Set('hmargin', 8)
.Set('strokestyle', 'white')
.Set('linewidth', 1)
.Set('shadow', true)
.Set('shadow.color', '#ccc')
.Set('shadow.offsetx', 0)
.Set('shadow.offsety', 0)
.Set('shadow.blur', 10)
.Draw();
}
</script>

That's because putting single quotes around your numbers turns them into strings - which are equivalent to 0. So you end up charting an array of zeros. RGraph then generates an appropriate scale of which the max is 1 - so a scale of 0.2, 0.4, 0.6, 0.8, 1. Then by default there's no decimals so they get rounded - producing 0,0,1,1,1.

Related

Calculate radius r = x^2 + y^2 using array values

I would like to use my calculated y[0] (x-values) and y[1] (y-values) from sol_3 using the solve_ivp to find the radius(r) and plot r(t).
How can I calculate r using x and y values from sol_r? I keep getting TypeError: only size-1 arrays can be converted to Python scalars.
It seems like I am having issues with data type.
Please find my code below:
timing = np.array([0,2*math.pi]) #t0 = 0 tf=2pi
sol_3 = solve_ivp(fun = motion, t_span=[-math.pi, 2*math.pi], y0 = initial, method='RK23')
x = (sol_3.y[0, :])
y = (sol_3.y[1, :])
r = math.sqrt(sol_3.y[1,:]**2+sol_3.y[0,:]**2)
The array of the sol_3 looks like this:
message: 'The solver successfully reached the end of the integration interval.'
nfev: 599
njev: 0
nlu: 0
sol: None
status: 0
success: True
t: array([-3.14159265, -3.14155739, -3.14120473, -3.13767817, -3.12223578,
-3.09595606, -3.0602884 , -3.01493539, -2.96220999, -2.90868487,
-2.86527118, -2.82204945, -2.76814683, -2.69499434, -2.61108567,
-2.51943819, -2.44000487, -2.36057156, -2.28852194, -2.20054302,
-2.10648128, -2.03001656, -1.97695204, -1.92388751, -1.87465566,
-1.82156056, -1.76673945, -1.73011416, -1.70585555, -1.68159695,
-1.64979671, -1.60847127, -1.55783888, -1.50388809, -1.45063319,
-1.40126952, -1.3488944 , -1.27797028, -1.19501887, -1.1039372 ,
-1.02086808, -0.95113058, -0.88636741, -0.80259334, -0.70932861,
-0.61584263, -0.55777683, -0.50936554, -0.46344206, -0.4113168 ,
-0.35663683, -0.31427459, -0.28317047, -0.25206634, -0.22135512,
-0.18102468, -0.13108896, -0.07689042, -0.02318517, 0.02738243,
0.07818198, 0.14701599, 0.22918967, 0.31978884, 0.41431515,
0.48493772, 0.55000025, 0.63412425, 0.72775963, 0.82162403,
0.87984573, 0.92849841, 0.97470164, 1.02711062, 1.0820909 ,
1.12462382, 1.15583674, 1.18704967, 1.21796912, 1.25856295,
1.30880593, 1.36330716, 1.41729713, 1.46809564, 1.51919004,
1.58841181, 1.67102044, 1.76206092, 1.85696013, 1.92801041,

BackgroundColor expression

I created a Base_Rent_Variance Calculated field that works like it should:
=IIF(Fields!CurrNrmRent.Value = 0 and Fields!PriorNrmRent.Value > 0, "Review", IIF(Fields!PriorNrmRent.Value = 0 and Fields!CurrNrmRent.Value > 0, "Review", IIF(Fields!CurrNrmRent.Value > 0 and Fields!PriorNrmRent.Value > 0, (Fields!CurrNrmRent.Value-Fields!PriorNrmRent.Value)/IIF(Fields!PriorNrmRent.Value = 0, 1, Fields!PriorNrmRent.Value), nothing)))
I am trying to create a BackgroundColor expression so that if Base_Rent_Variance >= 15% or <= -15%, the background color is red, and if it equals Review the color is red. The expression I created is filling the background red correctly for the 15% variances but not the Review. My expression is below. What am I doing wrong?
=IIF(Fields!Base_Rent_Variance.Value >= .15 or Fields!Base_Rent_Variance.Value <= -.15, "Red",iif(RTRIM(Fields!Base_Rent_Variance.Value) = "Review","Red","White"))
This is likely an issue with your datatypes. You're attempting to store both numeric and string types in the same field. I would use a conversion to be sure you have the correct datatypes. This expression should handle the mismatched datatypes.
=IIF(CDbl(Fields!Base_Rent_Variance.Value) >= .15 or CDbl(Fields!Base_Rent_Variance.Value) <= -.15,
"Red",
IIF(TRIM(CStr(Fields!Base_Rent_Variance.Value)) = "Review","Red","White"))
Another option to try is using the InStr function like the following.
=IIF(CDbl(Fields!Base_Rent_Variance.Value) >= .15 or CDbl(Fields!Base_Rent_Variance.Value) <= -.15,
"Red",
IIF(InStr(CStr(Fields!Base_Rent_Variance.Value), "Review"),"Red","White"))
Based on the comment below, let's try this one with a switch statement. The following switch statement will evaluate the first expression, set the cell red if true, check the second expression, set the cell red if true, and finally set anything left to white.
=SWITCH(CDbl(Fields!Base_Rent_Variance.Value) >= .15 or CDbl(Fields!Base_Rent_Variance.Value) <= -.15, "Red",
InStr(CStr(Fields!Base_Rent_Variance.Value), "Review"),"Red",
true, "White")
You can also use me.Value in colour expressions.
For example:
=iif(me.Value = "Review" OrElse me.Value >= 0.15 OrElse me.Value <= -0.15, "Red", "NoColor")
This means you don't have to recalculate your values each time, or keep track of changes in several locations if the calculations change.

Apache Solr heatmap : How to convert in usable coordinate int2d array returned by heatmap

I'm using faceting heatmap on a spatial field which then returns a 2d array like this
"counts_ints2D",
[
null,
null,
null,
null,
[
0,
8,
4,
0,
0,
0,
0,
0,
0,
...
I want to locate those cluster on the map but the problem is that I don't know how to convert that 2d array in geo coordinates.
There's absolutely no documentation out there showing what to do with those integer.
Can somebody give some guidance ?
Going with the data you gave for Glasgow, and using the formula given in the comments, lets explore the coordinates in a python repl:
# setup
>>> minX = -180
>>> maxX = 180
>>> minY = -53.4375
>>> maxY = 74.53125
>>> columns = 256
>>> rows = 91
# calculate widths
>>> bucket_width = (maxX - minX) / columns
>>> bucket_width
1.40625
>>> bucket_height = (maxY - minY) / rows
>>> bucket_height
1.40625
# calculate area for bucket in heatmap facet for x = 124, y = 13
# point in lower left coordinate
>>> lower_left = {
... 'lat': maxY - (13 + 1) * bucket_height,
... 'lon': minX + 124 * bucket_width,
... }
>>> lower_left
{'lat': 54.84375, 'lon': -5.625}
# point in upper right
>>> upper_right = {
... 'lat': maxY - (13 + 1) * bucket_height + bucket_height,
... 'lon': minX + 124 * bucket_width + bucket_width,
... }
>>> upper_right
{'lat': 56.25, 'lon': -4.21875}
Let's graph these points on a map, courtesy of open street map. We generate a small CSV snippet we can import on umap (select the up arrow, choose 'csv' as the type and enter content into the text box). To our coordinates to show:
>>> bbox = [
... "lat,lon,description",
... str(lower_left['lat']) + "," + str(lower_left['lon']) + ",ll",
... str(upper_right['lat']) + "," + str(lower_left['lon']) + ",ul",
... str(upper_right['lat']) + "," + str(upper_right['lon']) + ",uu",
... str(lower_left['lat']) + "," + str(upper_right['lon']) + ",lu",
... ]
>>> print("\n".join(bbox))
lat,lon,description
54.84375,-5.625,ll
56.25,-5.625,ul
56.25,-4.21875,uu
54.84375,-4.21875,lu
After pasting these points into the import box creating the layer, we get this map:
Map based on Open Street Map data through uMap. This area encloses Glasgow as you expected.
Here's some code that takes 180th meridian (date line) wrapping into account:
$columns = $heatmap['columns'];
$rows = $heatmap['rows'];
$minX = $heatmap['minX'];
$maxX = $heatmap['maxX'];
$minY = $heatmap['minY'];
$maxY = $heatmap['maxY'];
$counts = $heatmap['counts_ints2D'];
// If our min longitude is greater than max longitude, we're crossing
// the 180th meridian (date line).
$crosses_meridian = $minX > $maxX;
// Bucket width needs to be calculated differently when crossing the
// meridian since it wraps.
$bucket_width = $crosses_meridian
? $bucket_width = (360 - abs($maxX - $minX)) / $columns
: $bucket_width = ($maxX - $minX) / $columns;
$bucket_height = ($maxY - $minY) / $rows;
$points = [];
foreach ($counts as $rowIndex => $row) {
if (!$row) continue;
foreach ($row as $columnIndex => $column) {
if (!$column) continue;
$point = []
$point['count'] = $column;
// Put the count in the middle of the bucket (adding a half height and width).
$point['lat'] = $maxY - (($rowIndex + 1) * $bucket_height) + ($bucket_height / 2);
$point['lng'] = $minX + ($columnIndex * $bucket_width) + ($bucket_width / 2);
// We crossed the meridian, so wrap back around to negative.
if ($point['lng'] > 180) {
$point['lng'] = -1 * (180 - ($point['lng'] % 180));
}
$points[] = $point;
}
}

Error adding scale bar with map.scale

I manage to create a map and even include a north arrow, but can't get the map.scale to work and getting this kind of error:
Error in map.scale(x = -83, y = 12, ratio = FALSE, relwidth = 0.2, cex
= 0.6) : unused arguments (ratio = FALSE, relwidth = 0.2, cex = 0.6)
Here is the code:
library(maps)
library(mapdata)
library(ggmap)
library(mapproj)
library(maptools) #for shapefiles
library(scales) #for transparency
library(GISTools)
range <- readShapePoly("isthmanianpacificmoistforestecoregion") #layer of data for species range
map("worldHires", c('Cost', 'pan', 'Nic', 'Colombia'), xlim=c(-89,-75),ylim=c(5,13), col="lightgray", fill=TRUE) #plot the region I want
map.scale(-81,8,relwidth = 0.15, metric = TRUE, ratio = TRUE)
plot(range, add=TRUE, xlim=c(-89,-75),ylim=c(5,13), col=alpha("green", 0.6), border=TRUE)
map.scale(x=-80, y=10) #, relwidth=0.3, cex=0.5, ratio=FALSE)
north.arrow(xb=-77, yb=12, len=0.2, lab="N", col="black", fill=TRUE) #
The problem is that map.scale() is a function for both maps and GISTools packages. You are trying to use the function from the maps package. Since you are loading first maps and then GISTools, the map.scale() from maps is being masked (probably R throws a warning when loading the last package).
The solution is to specify the package in the function call:
maps::map.scale(-81,8,relwidth = 0.15, metric = TRUE, ratio = TRUE)
Also why two calls to map.scale? You should probably exclude one of them.

How to find a Mathematical Pattern in a Database?

So I have several tables (python but I am open to any languages/programs which could do this):
timestamp = {123234 , 2342343, 2342345 , ...}
good_bad = {1 , -1 , -1 , ...}
number_of_t = {4 , 3 , 5 ...}
user = {23 , 45 , 23 ...}
....
I want to know if it is possible to compare this table to a table of a traded stock :
time_stock = {123123, 123123, 123123, ....}
price_stock = {123, 122 , 121, ...}
and find coherences, logical pattern ...
most preferable in a function something like
good_bad(x)+2*number_of_t(x-4) - good_bad(x)^2 = time_stock(x+10)
x being the location in the table
of course for stock I would only want to know patterns which can predict the "FUTURE" but that does not change the main point of the question:
How can I find such patterns in a data set?

Resources