Mathematica: ListPlot with only special points lableld & PointSize - wolfram-mathematica

I tried now a couple of hours to get a 2D Listplot of the following kind.
A ListPlot data of points should have a "3rd coordinate" like time (years) running with them.
This works so far, but is just an example:
list={{2000,{12,6}},{2001,{13,9}},{2002,{15,12}},{2003,{19,15}},{2004,{24,20}},{2004,{31,26}}};
data=Table[{list[[k]][[2]],Text[Style[list[[k]][[1]],12,Black],list[[k]][[2]],{-2,0}]},{k,1,Length[list]}]
plot1=ListPlot[data[[All,1]],
PlotStyle->{AbsolutePointSize[7],Orange},
PlotRange->{{0,40},{0,40}},
Frame->True,
ImageSize->500
];
plot2=Graphics[data[[All,2]]];
Show[plot1,plot2]
But in my real data I have thousands of points, and I want only, say, every 100th data point labeled with the time marker, and every 100th point should have a different PointSize and color.
I could not do this so far.

I did what was suggested and separated the "special" points from the data. Here's a possible workaround.
fakedata=Table[{yrs,Flatten[{RandomInteger[40,1],RandomInteger[40,1]}]}, {yrs,2000,2100}];
data=Table[{fakedata[[k]][[2]],Text[Style[fakedata[[k]][[1]],12,Black],fakedata[[k]][[2]],{-2,0}]},{k,1,Length[fakedata]}];
plot1=ListPlot[data[[All,1]],
PlotStyle->{AbsolutePointSize[7],Blue},
PlotRange->{{-10,50},{-10,50}},
Frame->True,ImageSize->800
];
plot2=Graphics[data[[All,2]]];
Show[plot1,plot2]
But this labels all points. So I did the following (kind of ugly, I know...)
specialData=fakedata[[;;;;10]];
label=Table[{specialData[[k]][[2]],Text[Style[specialData[[k]][[1]],14,Red],specialData[[k]][[2]],{-1.5,0},Background->LightBlue]},{k,1,Length[specialData]}];
plot3=ListPlot[label[[All,1]],
PlotStyle->{AbsolutePointSize[7],Red},
PlotRange->{{-10,50},{-10,50}},
Frame->True,
ImageSize->800
];
plot4=Graphics[label[[All,2]]];
Show[plot1,plot3,plot4]

Related

Gremlin Sack Sum Once Per Distinct Value

Referencing this example from Practical Gremlin and this stack overflow post:
Gremlin Post Filter Path
g.withSack(0).V().
has('code','AUS').
repeat(out().simplePath().has('country',within('US','UK')).
choose(has('code','MAN'),sack(sum).by(constant(1)))).
until(has('code','EDI')).
where(sack().is(1)).
path().by('code').
limit(10)
Is it possible to perform a sack sum in such a way as to only sum the first time a property is found. For instance, instead of the 'code' property inside of the choose() which will only sum once per 'code' encountered thanks to the simplePath(), what if there was another property called 'airport_color'. As we perform the traversal, I would only want the sack sum to increment the first time it encountered 'blue' or 'white' as an example, even though multiple airports could have the same color as we go through the traversal. This would help me in the where() clause because, if I had a couple of colors I was interested in looking for as an example (maybe blue and white), I could set the where() clause to be equal to two and know that two wasn't arrived at just because I passed through blue twice but because blue and white was encountred.
I tried using aggregation to make the sack sum increment only on the first encounter but couldn't get it to work, something like this:
g.withSack(0).V().
has('code','AUS').
repeat(out().simplePath().has('country',within('US','UK')).
choose(has('airport_color','blue').has('airport_color', without('airport_color_agg')),sack(sum).by(constant(1))).
aggregate('airport_color_agg').by('airport_color')).
until(has('code','EDI')).
where(sack().is(1)).
path().by('code').
limit(10)
There could be multiple colors in the choose() via or() but I limited it to just one to keep the example more straightforward.
Thanks for your help!
Using the sample graph below:
g.addV('A').property(id,'a1').property('color','red').as('a1').
addV('A').property(id,'a2').property('color','blue').as('a2').
addV('A').property(id,'a3').property('color','red').as('a3').
addV('A').property(id,'a4').property('color','yellow').as('a4').
addV('A').property(id,'a5').property('color','green').as('a5').
addV('A').property(id,'a6').property('color','blue').as('a6').
addE('R').from('a1').to('a2').
addE('R').from('a2').to('a3').
addE('R').from('a3').to('a4').
addE('R').from('a4').to('a5').
addE('R').from('a5').to('a6')
we can inspect the path through the graph as follows:
g.V('a1').
repeat(out()).
until(not(out())).
path().
by('color')
which shows us the colors found
path[red, blue, red, yellow, green, blue]
the next thing we need to do is to remove the duplicates and filter out the colors not in our want list.
g.withSideEffect('want',['red','green']).
V('a1').
repeat(out()).
until(not(out())).
path().
by('color').
dedup(local).
unfold().
where(within('want'))
which gives us:
red
green
finally, we just need to count them:
g.withSideEffect('want',['red','green']).
V('a1').
repeat(out()).
until(not(out())).
path().
by('color').
dedup(local).
unfold().
where(within('want')).
count()
Which, as expected, gives us:
2
UPDATED 2022-09-01 To reflect discussion in comments.
To change the query so that only paths that visit each of the required colors at least once are returned, the previous steps leading up to the count need to be turned into a filter.
g.withSideEffect('want',['red','green']).
V('a1').
repeat(out()).
until(not(out())).
filter(
path().
by('color').
dedup(local).
unfold().
where(within('want')).
count().is(2)).
path()
which for our sample graph returns:
1 path[v[a1], v[a2], v[a3], v[a4], v[a5], v[a6]]
The query as written gets the job done and hopefully is not too hard to follow. There are some things we could change/improve.
Pass in the count for the is step as another parameter like the want list.
Rather than pass in a parameter, use the size of the want list instead. This makes the query a little more complex.
Use a sack as the query proceeds to collect the colors seen. The query gets more complex in that case as, while you can maintain a list in a sack, updating it requires a few extra steps.
Here is the query rewritten to use a sack. This assumes the start node has a color that should be included. If that is not the case, the first sack(assign) can be removed and a withSack([]) added after the withSideEffect.
g.withSideEffect('want',['red','green']).
V('a1').
sack(assign).by(values('color').fold()).
repeat(out().sack(assign).by(union(sack().unfold(),values('color')).fold())).
until(not(out())).
filter(
sack().
unfold().
dedup().
where(within('want')).
count().is(2)).
path()

Ruby SketchUp ... add a measurment

still learning about Ruby + Sketchup!
Today,I would like to add a measurement (good english word ?) as I can do manually with the 'cotation' (french version) tool when I click to point then drag the measure text.
Can't find that in the docs to do with Ruby and API ...
Thanks for your help
You are probably looking for the Sketchup::Entities::add_dimension_linear method.
http://ruby.sketchup.com/Sketchup/Entities.html#add_dimension_linear-instance_method
Assuming a and b below are edges
voffset = [-20, 0, 0]
Sketchup.active_model.entities.add_dimension_linear(a.start, b.start, voffset)
The value of voffset controls not just how far offset the dimension is, but also the axis along which the measurement is made. You may need to experiment with different values to get a feeling for how that determination is done. As with many things in SketchUp, it often guesses (or 'infers') at what you want.

Paraview rotate fields

I am using Paraview 5.0.1. If any solution requires updating, I can try.
I want to programmatically obtain field plots (and corresponding PlotOverLine) of displacements and stresses in rotated coordinate systems.
What are appropriate/convenient/possible ways of doing this?
So far, I have created one Calculator filter for each component of displacements and stresses.
For instance, I used Calculators in 2D with results
(displacement.iHat)*cos(0.7853981625)+(displacement.jHat)*sin(0.7853981625)
(stress_3-stress_0)*sin(45.0*3.14159265/180)*cos(45.0*3.14159265/180)+stress_1*((cos(45.0*3.14159265/180))^2-(sin(45.0*3.14159265/180))^2)
It works fine, but it is quite cumbersome, in several aspects:
Creating them (one filter per component).
Plotting several of them in a single XY plot
Exporting them (one export per component).
Is there a simple way to do this?
PS: The Transform filter does not accomplish this. It rotates the view, not the fields.
Two solutions:
Ugly, inneficient solution
Use Transform and check "Transform All Input vectors"
Add a calculator and add a dummy array
Use transform the other way around, without checking "Transform All Input vectors"
Correct solution :
Compute the transformation yourself in a programmable filter
input = self.GetUnstructuredGridInput();
output = self.GetUnstructuredGridOutput();
output.ShallowCopy(input)
data = input.GetPointData().GetArray("YourArray")
vec = vtk.vtkDoubleArray();
vec.SetNumberOfComponents(3);
vec.SetName("TransformedVectors");
numPoints = input.GetNumberOfPoints()
for i in xrange(0, numPoints):
tuple = data.GetTuple(i)
transform(tuple) # implement the transform in python
vec.InsertNextTuple(tuple)
output.GetPointData().AddArray(vec)

highcharts remove redundant data points to improve speed

i am drawing a simple line chart with highcharts. one chart can include many many points which introduces delay when playing around with the chart.
since many data-points are redundant i came up with the idea of not adding a new data-point if the value is the same as the previous one. this reduces the amount of data, but should still result in the same graph.
please see this example: http://jsfiddle.net/qm94j14t/1/
i would like to have one straight line without the data-points from February until November.
right now the data array looks like this:
data: [7,7,7,7,7,7,7,7,7,7,7,10]
What do i need to change in the code to get a straight line without these redundant 7 values?
Instead of using [y_1, y_2, ... , y_n] format, use [ [x_1, y_1], [x_2, y_2] , ... , [x_n, y_n]] format.
Then remove redundant data, demo: http://jsfiddle.net/qm94j14t/7/ So in your case it's [[0,7], [9, 7], [10, 10]].

R: Which heatmap/image to get row-sorted plot without any dendrogram?

Which package is best for a heatmap/image with sorting on rows only, but don't show any dendrogram or other visual clutter (just a 2D colored grid with automatic named labels on both axes). I don't need fancy clustering beyond basic numeric sorting. The data is a 39x10 table of numerics in the range (0,0.21) which I want to visualize.
I searched SO (see this) and the R sites, and tried a few out. Check out R Graphical Manual to see an excellent searchable list of screenshots and corresponding packages.
The range of packages is confusing - which one is the preferred heatmap (like ggplot2 is for most other plotting)? Here is what I found out so far:
base::image - bad, no name labels on axes, no sorting/clustering
base::heatmap - options are far less intelligible than the following:
pheatmap::pheatmap - fantastic but can't seem to turn off the
dendrograms? (any hacks?)
ggplot2 people use geom_tile, as Andrie points out
gplots::heatmap.2 , ref - seems
to be favored by biotech people, but way overkill for my purposes. (no
relation to ggplot* or Prof Wickham)
plotrix::color2D.matplot also exists
base::heatmap is annoying, even with args heatmap(..., Colv=NA, keep.dendro=FALSE) it still plots the unwanted dendrogram on rows.
For now I'm going with pheatmap(..., cluster_cols=FALSE, cluster_rows=FALSE) and manually presorting my table, like this guy: Order of rows in heatmap?
Addendum: to display the value inside each cell, see: display a matrix, including the values, as a heatmap . I didn't need that but it's nice-to-have.
With pheatmap you can use options treeheight_row and treeheight_col and set these to 0.
just another option you have not mentioned...package bipartite as it is as simple as you say
library(bipartite)
mat<-matrix(c(1,2,3,1,2,3,1,2,3),byrow=TRUE,nrow=3)
rownames(mat)<-c("a","b","c")
colnames(mat)<-c("a","b","c")
visweb(mat,type="nested")

Resources