How to extract only the data points from BodePlot plot? - wolfram-mathematica

I am trying to fix the Phase plot part of BodePlot, as it does not wrap correctly. And there is no option that I can use to tell it to wrap.
So, instead of doing the full plot myself, (I can do that if I have to) I am thinking of first making the BodePlot, grab the data points, do the wrapping on the data (once I get the x,y data, the rest is easy), then I need to put the new list of points back into the plot, and then use Show to display it.
The part I am stuck at, is extracting the points from FullForm. I can't get the correct Pattern to do that.
This is what I go to so far:
hz=z/(z^2-z+0.3);
tf=TransferFunctionModel[hz,z,SamplingPeriod->2];
phasePlot=BodePlot[tf,{0.001,2 Pi},
ScalingFunctions->{Automatic,{"Linear","Degree"}},PlotLayout->"List"][[2]]
You see how it does not wrap at 180 degrees. It is more common in dsp that Bode phase plot wraps. Here is what it 'should' look like:
So, this is what I did:
FullForm[phasePlot]
Graphics[List[
List[List[], List[],
List[Hue[0.67, 0.6, 0.6],
Line[List[List[0.0010000243495554542, -0.2673870119911639],
List[0.0013659538057574799, -0.36521403872250247],
List[0.0017318832619595053, -0.46304207336414027],
....
I see the data there (the x,y) But how to pull them out? I tried this:
Cases[FullForm[phasePlot], List[x_, y_] -> {x, y}, Infinity];
But the above matches in addition to the list of point, other stuff that I do not need.
I tried many other things, but can't get only the list of points out.
I was wondering if someone knows how to pull only the (x,y) points from the above plot. Is there a better way to do this other than using FullForm?
Thanks
Update:
I just find a post here which shows how to extract data from plot. So I used it:
points = Cases[Normal#phasePlot, Line[pts_] -> pts, Infinity]

You could do try nesting the replacement rules, for example
phase2 = phasePlot /.
Line[a_] :> (Line[a] /. {x_?NumericQ, y_?NumericQ} :> {x, Mod[y, 360, -180]});
Show[phase2, PlotRange -> {Automatic, {-180, 180}}, FrameTicks -> Automatic]
Output:

The list you are looking for appears to be wrapped by Line[], and it seems to be the only case in your plot. So you could use
Cases[phasePlot, Line[list_] :> list, Infinity]
Edit:
When I posted my response, the page refreshed and I saw that you came across precisely what I had proposed. I'll leave my response posted here anyway.
Edit2:
Szabolics pointed out that FullForm[] has no effect, so I removed it from my original posting.

Related

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.

Mathematica: ListPlot with only special points lableld & PointSize

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]

matplotlib in ipython notebook: need functionality like manipulate function in Mathematica

I occasionally use Mathematica to create animated graphs with parameters that I can change in real time as the animation runs. I find this is particularly effective to demonstrate the behavior of physical systems for students. An example Mathematica for one of the simpler animations is:
freq = 100*^6
lambda = 3*^8/freq
alpha = 0
TLineLength = 10*lambda
AmplitudePlus = 2
PhasePlus = (2*Pi/180)*0
AmplitudeMinus = AmplitudePlus*0.5
PhaseMinus = (2*Pi/180)*0
GammaL = 0
Manipulate[Plot[AmplitudePlus*Cos[2*Pi*freq *t - (2*Pi/lambda)*z + PhasePlus]*
Exp[-alpha*(TLineLength + z)], {z, -TLineLength, 0},
PlotRange -> AmplitudePlus, AxesLabel -> {z [m], SuperPlus[V]}], {t,
0, 10/freq}, {PhasePlus, 0, 2*Pi}, {alpha, 0, 1/(2*lambda)}]
I would love to do this in ipython notebooks instead of Mathematica. I have tried using interact similar to the answers to this question, but interact does not support animations as far as I've been able to determine. Also, generated graphs have a lot of flicker as you move a slider widget to control a parameter. I've also tried FuncAnimate, but have been entirely unsuccessful getting this to run inline in an ipython notebook (which I'm running on mac OS X 10.9). Even if I could get it to run, I wouldn't be able to change any parameters in real time as the animation runs. I would welcome advice or suggestions.

Stop different Manipulate Panels from triggering each other

This should be a simple question, but I have given up on it after a while now.
I have different input lines which I have evaluated in a single notebook. Two of these have manipulate statements:
The first one
Manipulate[{ Some Plot Func }, {{\[Omega]0, 3}, 0, 3}, {{\[Tau], 5}, -1, 20}]
The second One:
Manipulate[{ Some Plot Func }, {Twave, 1, 10}, {{Tenv, 10}, 0, 100}, TrackedSymbols :> True]
When I change parameters in the second one, i can see the first one evaluating as well.
I have tried specifying with TrackedSymbols to disentangle the two, but this does not succeed. I hope someone can point me to the obvious solution. It is slowing down evaluation a lot.
Thank you!
How about this?
End each of your manipulates with a semicolon.
Create a third "master" manipulate which does not end with a semicolon.
Within the master manipulate, use a TabView. With each pane of the tab, run one of your manipulates by calling it like a function. It is convenient to create a list of your manipulates and pick the one to execute with a "tab index" of sorts.
I've gotten this to work well with several manipulates, rules for moving between them via the tabs, and so forth. It's proven to be a useful approach for notebook applications,as the complexity of one giant manipulate gets out of hand.

Mathematica: AbsoluteOptions not working properly

According to the documentation AbsoluteOptions[expr,name] "gives the absolute setting for the option name".
"AbsoluteOptions gives the actual settings for options used internally by Mathematica when the setting given is Automatic or All."
Here is an example they show:
<< AbsoluteOptions[Plot[Sin[x], {x, 0, 2 Pi},
PlotRange -> Automatic], PlotRange]
>> {PlotRange -> {{0., 6.28319}, {-1., 1.}}}
Here I use << to denote Input and >> to denote output.
This seems to work fine. However, when I try to obtain the AspectRatio of a plot it simply gives me Automatic. Try this,
AbsoluteOptions[
ListPlot3D[{{1, 1, 1, 1}, {1, 2, 1, 2}, {1, 1, 3, 1}, {1, 2, 1, 4}},
AspectRatio -> Automatic],
AspectRatio
]
Similar format as the example they show but the output I get is simply
{AspectRatio->Automatic}
Does this mean that the argument expr can only be a Graphics object and not Graphics3D? This doesn't make sense because it works fine if I try to obtain the PlotRange of a Graphics3D object. Is this a bug or my mathematica is broken? Another thing could be that the documentation is not being very specific. Which one is it?
Here is a link to the documentation:
http://reference.wolfram.com/mathematica/ref/AbsoluteOptions.html
I'm using Mathematica 7.0.1.0.
You can apply ImageDimensions directly to Graphics3D to get its ImageSize.
It seems that AbsoluteOptions just was not modified since Mathematica 4 (see bottom of the corresponding documentation page). This function is very buggy (often gives wrong value for PlotRange for 2D graphics generated by Show, for example) and sometimes does not work at all as you pointed in your question. Compare it with FullOptions and FullGraphics those are seemed to be not modified since version 2... Sometimes FullOptions gives right value when AbsoluteOptions gives wrong or does not work at all.
Maybe, BoxRatios is the one you are looking for. HTH.

Resources