It's my first time asking for help here, I hope someone respond. I was hoping to post images to show the problem I had but I need at least 10 reps to do it. But I hope everyone understand what I'm asking for.
I'm trying to create a manipulate box to plot a transfer function with type in boxes so that I can type in the the transfer function and specify the x and y axis. But the plot itself is not appearing only the axis are
but if i type the code outside of "manipulate" it works.
If you try running this on Mathematica you could probably see the problem I'm having.
My mathematica code is below.
Manipulate[tfplot,
{{tfplot1, 0, "Transfer Function="}},
Delimiter,
{{fmin1, 10, "fmin = "}},
{{fmax1, 10^7, "fmax = "}},
{{ymin1, 1, "ymin = "}},
{{ymax1, 2*10^2, "ymax = "}},
Delimiter,
Row[{
Button["Plot", tfplot = LogLogPlot[Abs[tfplot2[2*Pi*I*f] /. {tfplot2[s_] -> tfplot1}], {f, fmin1, fmax1}, PlotPoints -> 1000, PlotRange -> {{fmin1, fmax1}, {ymin1, ymax1}}, PlotLabel -> "tf Plot"], ImageSize -> 80]
}]
, ControlPlacement -> {Left, Left, Left, Left, Left, Left, Left, Top}]
tfplot3 = (3.333321894500285`*^6 (4.611679331492357`*^6 - 72057.48955456808` s - 4.138291871540356`*^9 s^3 - 3.889993968666704`*^9 s^4 + s^5))/(s^2 (2.606152799059127`*^18 + 4.6278171788297256`*^16 s + 1.0779994813998577`*^14 s^2 + 1.5235290577558628`*^8 s^3 + s^4))
LogLogPlot[Abs[tfplot4[2*Pi*I*f] /. {tfplot4[s_] -> tfplot3}], {f, 10, 10^7}, PlotPoints -> 1000, PlotRange -> {{10, 10^7}, {1, 2*10^2}}, PlotLabel -> "tf Plot"]
Thank you.
Spiderfiq
Edit .. take 2..
Manipulate[
fplot = LogLogPlot[Abs[tfplotf /. s -> 2*Pi*I*f], {f, fmin1, fmax1},
PlotPoints -> 1000, PlotRange -> {{fmin1, fmax1}, {ymin1, ymax1}},
PlotLabel -> "tf Plot"],
{{tfplotf, (3.333321894500285`*^6 (4.611679331492357`*^6 -
72057.48955456808` s - 4.138291871540356`*^9 s^3 -
3.889993968666704`*^9 s^4 +
s^5))/(s^2 (2.606152799059127`*^18 +
4.6278171788297256`*^16 s + 1.0779994813998577`*^14 s^2 +
1.5235290577558628`*^8 s^3 + s^4))
, "Transfer Function="}},
Delimiter,
{{fmin1, 10, "fmin = "}},
{{fmax1, 10^7, "fmax = "}},
{{ymin1, 1, "ymin = "}},
{{ymax1, 2*10^2, "ymax = "}},
Delimiter,
ControlPlacement -> {Left, Left, Left, Left, Left, Left, Left, Top}]
This is some old code I had lying around from my System Dynamics and Controls class.
Manipulate[tf = TransferFunctionModel[eq, s];
BodePlot[tf, GridLines -> Automatic, ImageSize -> 500,
FrameLabel -> {{{"magnitude (db)", None}, {None,
"Bode plot"}}, {{"phase(deg)", None}, {"Frequency (rad/sec)",
None}}},
ScalingFunctions -> {{"Log10", "dB"}, {"Log10", "Degree"}},
PlotRange -> {{{0.1, 100}, Automatic}, {{0.1, 100},
Automatic}}], {eq, (5 s)/(s^2 + 4 s + 25)}]
-Brian
Related
I have data which I would like to plot along with the corresponding error bars:
{{{54927.7, -1.91044}, ErrorBar[38.2664, 0.0538982]},
{{55320.9, -1.97673}, ErrorBar[45.3592, 0.101486]},
{{55671.4, -2.15716}, ErrorBar[41.2234, 0.0258249]},
{{56032.9, -2.15957}, ErrorBar[38.8805, 0.0191277]},
{{56410.6, -2.14289}, ErrorBar[41.5501, 0.0189911]},
{{56787.2, -2.19703}, ErrorBar[38.1972, 0.00632055]},
{{57137.5, -2.1839}, ErrorBar[35.6098, 0.0084108]},
{{57493.3, -2.19994}, ErrorBar[38.0298, 0.00651633]},
{{57859.5, -2.19687}, ErrorBar[40.9682, 0.00658857]}}
I can use the "ErrorListPlot" function in *Mathematica just fine, however if I would like to reverse the y axis scale with the function "ScalingFunctions->"Reverse" " the error bars do not get plotted along with the data.....any suggestions on how to fix this?
Similar to this question. Some messing around to get the ticks looking right.
Needs["ErrorBarPlots`"]
data = {
{{54927.7, -1.91044}, ErrorBar[38.2664, 0.0538982]},
{{55320.9, -1.97673}, ErrorBar[45.3592, 0.101486]},
{{55671.4, -2.15716}, ErrorBar[41.2234, 0.0258249]},
{{56032.9, -2.15957}, ErrorBar[38.8805, 0.0191277]},
{{56410.6, -2.14289}, ErrorBar[41.5501, 0.0189911]},
{{56787.2, -2.19703}, ErrorBar[38.1972, 0.00632055]},
{{57137.5, -2.18390}, ErrorBar[35.6098, 0.0084108]},
{{57493.3, -2.19994}, ErrorBar[38.0298, 0.00651633]},
{{57859.5, -2.19687}, ErrorBar[40.9682, 0.00658857]}};
data[[All, 1, 2]] = -data[[All, 1, 2]];
ep = ErrorListPlot[data];
newTicks = AbsoluteOptions[ep, Ticks][[1, 2, 2]] /.
{x1_, x2_, x3_, x4_} :> If[x1 == x2,
{x1, NumberForm[-x2, {3, 2}], {0.014, 0}, x4},
{x1, x2, {0.007, 0}, x4}];
newTicks = newTicks /. {
GrayLevel[0.] -> GrayLevel[0.5],
AbsoluteThickness[0.25] -> AbsoluteThickness[0.18],
AbsoluteThickness[0.125] -> AbsoluteThickness[0.08]};
ErrorListPlot[data, Ticks -> {Automatic, newTicks}]
Needs["ErrorBarPlots`"]
data = {
{{54927.7, -1.91044}, ErrorBar[38.2664, 0.0538982]},
{{55320.9, -1.97673}, ErrorBar[45.3592, 0.101486]},
{{55671.4, -2.15716}, ErrorBar[41.2234, 0.0258249]},
{{56032.9, -2.15957}, ErrorBar[38.8805, 0.0191277]},
{{56410.6, -2.14289}, ErrorBar[41.5501, 0.0189911]},
{{56787.2, -2.19703}, ErrorBar[38.1972, 0.00632055]},
{{57137.5, -2.18390}, ErrorBar[35.6098, 0.0084108]},
{{57493.3, -2.19994}, ErrorBar[38.0298, 0.00651633]},
{{57859.5, -2.19687}, ErrorBar[40.9682, 0.00658857]}};
(* Invert the error bars, visible in InputForm *)
ep = InputForm[ErrorListPlot[data]] /.
{Line[{{a_, b_}, {c_, d_}}] :> Line[{{a, -b}, {c, -d}}],
Line[{Offset[e_, {f_, g_}], Offset[h_, {i_, j_}]}] :>
Line[{Offset[e, {f, -g}], Offset[h, {i, -j}]}]};
(* Discard the InputForm wrapper *)
ep2 = First[ep];
Show[ErrorListPlot[data, ScalingFunctions -> "Reverse"],
Delete[ep2, Most#First#Position[ep2, Point]]]
I made my graph in Mathematica and then I exported them as eps to my folder. Then I use Latex to use them in my document. Until today it was working perfectly but I have no clue how, my Mathematica cannot export the figure properly (I am using Ubuntu).
The correct format of the plot
Incorrect format of the plot. This is the one that I am getting now
If someone has any idea please let me know.
Mathematica code:
ClearAll["Global`*"]
p = {1000, 1200, 600, 1200};
u = {0.001, 0.5, 5*10^(-5), 0.05};
pu = p/u;
logy1[x_] = Log10[pu[[1]]] + x;
logy2[x_] = Log10[pu[[2]]] + x;
logy3[x_] = Log10[pu[[3]]] + x;
logy4[x_] = Log10[pu[[4]]] + x;
g1 = Plot[{logy1[x], logy2[x], logy3[x], logy4[x]}, {x,
Log10[5*10^(-5)], Log10[0.01]},
PlotStyle -> {{Black, Thickness[0.007]}, {Black, Thickness[0.007],
Dashing[{0, 0.02}]}, {Black, Thickness[0.007],
Dashing[{0, 0.02, 0.02, 0.02}]}, {Black, Thickness[0.007],
Dashing[0.02]}},
AxesLabel -> {Text[
Style["Log(q/H)", Bold, 18]],
Text[Style["Log(Re)", Bold, 18]]}, ImageSize -> 700,
PlotLegends -> {Text[Style["Water", Bold, 18]],
Text[Style["X-Linked Gel", Bold, 18]],
Text[Style["CO2 (Supercritical)",
Bold, 18]], Text[Style["Linear Gel", Bold, 18]]},
AxesOrigin -> {Log10[5*10^(-5)], -2},
PlotRange -> {{Log10[5*10^(-5)], -2}, {-2, 8}},
BaseStyle -> {FontWeight -> "Bold", FontSize -> 18}];
Export["Figure.eps", g1]
Latex code:
\begin{figure}
\centering
\includegraphics[height=60mm]{./figure/Figure.eps}
\caption{My figure.}
\label{Figure}
\end{figure}
Please consider :
dalist = {{379, 219, 228, 401}, {387, 239, 230, 393},
{403, 238, 217, 429}, {377, 233, 225, 432}}
BarChart[dalist,
Frame -> True,
FrameTicks -> {{None, None}, {None, None}}]
I can`t figure out the way to deal with the ticks themselves and the range (the numbers). I would like to see the Range but not the ticks like the below :
EDIT :
Having solved some problem, it seems I created new ones.
To Summarize, I would like to see :
TicksLabel but not the Ticks (solved)
FrameLabel but not the Frame.
The Below shall illustrate the problem. FrameStyle control the Frame Label.
So applying opacity[0] to FrameStyle to hide the frame hides the frame Label.
BarChart[Range[10],
ChartStyle -> Black,
PlotRangePadding -> 0,
Frame -> {{True, False}, {True, False}},
FrameLabel -> {{"Why?", None}, {"Because !", None}},
FrameTicksStyle -> Opacity[1],
FrameStyle -> Opacity[0],
PlotLabel -> Style["Bonjour", Bold, 16, Opacity[1]],
LabelStyle -> Directive[Black, Bold, 12, Opacity[1]],
ImageSize -> 400]
Ticks and FrameTicks have optional more complex syntax, where each tick can be specified as {x,label,{length_inside,length_outside}}
So to have ticks labels without ticks, specify the second pair of numbers as two zeros.
To replicate the ticks in your example, you would use
FrameTicks->{{Table[{j,j,{0,0}},{j,0,300000,50000}],None},
{Table[{k,k,{0,0}},{k,2010,2015}],None}}
For BarCharts, the bars are at 1, 2, 3... x-positions, so this needs to be:
FrameTicks->{{Table[{j,j,{0,0}},{j,0,300000,50000}],None},
{Table[{k,k+2009,{0,0}},{k,1,6}],None}}
As requested in comments, if you want numbers but no ticks and no frame, add:
FrameTicksStyle -> Opacity[1], FrameStyle -> Opacity[0]
EDIT And use Style on any frame labels.
End result:
data = RandomReal[{0, 300000}, {10}]
BarChart[data,
FrameTicks -> {{Table[{j, j, {0, 0}}, {j, 0, 300000, 50000}],
None}, {Table[{k, k + 2009, {0, 0}}, {k, 1, 10}], None}},
Frame -> True, FrameTicksStyle -> Opacity[1], FrameStyle -> Opacity[0],
FrameLabel -> {{Style["Why?", Opacity[1]], None},
{Style["Axes", Opacity[1]], None}}]
My answer to this question might help illuminate.
Perhaps you are looking for ChartLabels:
BarChart[dalist, ChartLabels -> Placed[Flatten#dalist, Below],
FrameTicks -> {{Automatic, None}, {None, None}},
Frame -> True,
Ticks -> None]
I sometimes run into the problem of labels in TreeForm being unreadable because of overlap. An example is below, can anyone see a way to get rid of overlap?
{{4, 5, 6}, {{{2, 4, 5, 6}, {{{1, 2, 4}, {}}, {{2, 3, 6}, {}}}}, {{4,
5, 6, 8}, {{{4, 7, 8}, {}}, {{6, 8, 9}, {}}}}}} // TreeForm
(source: yaroslavvb.com)
Belisarius' solution helps with overlap, but loses Tooltips, ie compare with
TreeForm[Hold[
GraphPlotHighlight[edges : {((_ -> _) | {_ -> _, _}) ...},
hl : {___} : {}, opts : OptionsPattern[]] :=
Module[{verts, coords, g, sub}, 5]]]
(source: yaroslavvb.com)
Answer update 11/12
I ended up using code below (belisarius' code with a minor fix)
myTreeForm[exp_] :=
Module[{tooltipText, i},
tooltipText =
Cases[Cases[MakeBoxes[TreeForm#exp, StandardForm],
TooltipBox[x__] -> x, 7, Heads -> True],
TagBox[x__, y__] -> DisplayForm[First#{x}], Heads -> True];
i = 0;
TreeForm[exp,
VertexRenderingFunction -> ({Tooltip[
Inset[Rasterize[Text[" " <> ToString##2 <> " "],
Background -> LightBlue], #1], tooltipText[[i++]]]} &)]];
I did this before, but never generalized the result.
rectOffset = {.25,.1};
fontSize = 10
TreeForm[list,
VertexRenderingFunction -> ({White, EdgeForm[Black],
Rectangle[#1 - rectOffset, #1 + rectOffset], Black,
Text[ Style[#2, fontSize], #1]} &)]
Edit With Tooltips
Using a "different approach"
Code is dirty, sorry no time to clean it up right now
rectOffset = {.33, .1};
fontSize = 9;
p = Cases[
Cases[MakeBoxes[TreeForm#list, StandardForm], TooltipBox[x__] -> x,
7, Heads -> True], TagBox[x__, y__] -> DisplayForm[First#{x}],
Heads -> True];
i = 0;
TreeForm[list,
VertexRenderingFunction -> ({White, EdgeForm[Black],
Rectangle[#1 - rectOffset, #1 + rectOffset], Black,
Tooltip[Text[Style[#2, fontSize], #1], p[[i++]]]} &)]
Output
Edit 2
I think this version is better:
Clear["Global`*"];
list = Hold[
GraphPlotHighlight[edges : {((_ -> _) | {_ -> _, _}) ...},
hl : {___} : {}, opts : OptionsPattern[]] :=
Module[{verts, coords, g, sub}, 5]];
myTreeForm[exp_] :=
Module[{ps, tooltipText, i},
ps[text_] := Rasterize[Text[Style[text]], "RasterSize"];
tooltipText =
Cases[Cases[MakeBoxes[TreeForm#list, StandardForm],
TooltipBox[x__] -> x, 7, Heads -> True],
TagBox[x__, y__] -> DisplayForm[First#{x}], Heads -> True];
i = 0;
TreeForm[list,
EdgeRenderingFunction -> ({Red, Line[#1]} &),
VertexRenderingFunction -> ({White, EdgeForm[Black], {}, Black,
Tooltip[
Inset[Rasterize[Text[" " <> ToString##2 <> " "],
Background -> LightBlue], #1], tooltipText[[i++]]]} &)]
];
list // myTreeForm
Output:
Edit 4 ... and last one
Cleaned up code, remove spurious functions and variables that were there just to complicate things:
myTreeForm[list_] := Module[{tooltipText, i},
tooltipText =
Cases[Cases[MakeBoxes[TreeForm#list, StandardForm],
TooltipBox[x__] -> x, 7, Heads -> True],
TagBox[x__, y__] -> DisplayForm[First#{x}], Heads -> True];
i = 0;
TreeForm[list,
VertexRenderingFunction ->
({Tooltip[Inset[Rasterize[Text[" " <> ToString##2 <> " "],
Background -> LightBlue], #1], tooltipText[[i++]]]} &)
]
];
HTH!
It looks as if the option VertexCoordinateRules may be your best hope.
I am trying to use GraphPlot function to build a Graph, where each node is an image. I wanted to display the image as my vertex. Does anybody know how to do this?
I tried something like this:
GraphPlot[ Map[If[# > 2.0 , 0, 1] &,
imgDistT, {2}],
VertexRenderingFunction -> (Inset[imgs[[#2]], #1, Center] &) ]
But this does not work.
imgs is my list of images corresponding to each vertex number.
As a sanity check, if i do this:
GraphPlot[
Map[If[# > 2.0 , 0, 1] &, imgDistT, {2}],
VertexRenderingFunction -> (Inset[Text[#2], #1, Center] &) ]
then that works and it shows me the vertex number at each node.
imgs = ExampleData /# ExampleData["TestImage"];
GraphPlot[{1 -> 4, 1 -> 5, 2 -> 3, 2 -> 4, 2 -> 5, 3 -> 4, 3 -> 5},
VertexRenderingFunction -> (Inset[Image[imgs[[#2]], ImageSize -> 100], #1] &)]
Edit
-- Infix notation joke removed --
Two possible issues:
It looks like your graph, Map[If[# > 2.0 , 0, 1] &, imgDistT, {2}], will contain zeroes and ones—but zeroes are invalid indices for the imgs array
The images may not appear properly due to scaling issues—for example, they might be really big only the white portion might be visible. Try specifying an explicit image size.
What is the output of
GraphPlot[Map[If[# > 2.0 , 0, 1] &, imgDistT, {2}],
VertexRenderingFunction -> (Module[{tmp =
Inset[Image[imgs[[#2]], ImageSize -> 10], #1, Center]},
Print[tmp]; tmp] &)]
?