Putting a VerticalSlider into Mathematica's Manipulate? - wolfram-mathematica

How do you set up manipulate so that you can control a variable with a vertical slider instead of a horizontal slider in Mathematica?

From the help ....
Manipulate[u, {u, 0, 1, ImageSize -> Small},
ControlType -> VerticalSlider, ControlPlacement -> Left]

Related

Mathematica: Unwanted vertical line in histogram

When changing the plot range of a histogram from Automatic to a plot range which exceeds the automatically calculated plot range, Mathematica draws an unwanted horizontal line which I cannot get rid of (see right histogram at value -4). Does anyone have a suggestion on that issue?
I'm running Mathematica V.8.0.1.0 on Mac OS 10.7.2.
In[1099]:=
data = {-1.2056, -1.46192, -1.30053, -2.52879, -0.99636, -1.73904, -1.164,
-1.83398,-0.97505, -0.503256, -0.63802, -0.785963, -0.711821, -0.820439, -1.8699,
-3.9659, -1.4456, -1.67021, -1.42009, -2.5644, -1.45002, -1.27806, -1.66529,
-1.67073, -3.31102, -3.38638};
HistogramLeft=Histogram[data, PlotRange -> Automatic]
HistogramRight=Histogram[data, PlotRange -> {-8, 0}]
It looks like you're using Frame -> {{True, False}, {True, False}} (or something similar.) If that's the case, you can turn off the normal axes entirely with Axes->False.
Look at the option AxesOrigin.
HistogramRight = Histogram[data, PlotRange -> {-8, 0}, BarOrigin -> Left, AxesOrigin -> {-8, 0}]
If I understand what you want, this is pretty easy, I think.
Try
HistogramRight =
Histogram[data, PlotRange -> {-8, 0}, BarOrigin -> Left,
PlotLabel -> Left, Axes -> {False, True}]
By the way, there is a new stack exchange for Mathematica at https://mathematica.stackexchange.com/

How to not show the scrollbars when ContentSize does not fit the content in Manipulate?

This is an example of what I'd like to do: Do all the display in the control area of Manipulate itself:
Manipulate[
p = Framed#
Plot[Sin[x],{x, -y, y},ImageSize->300,Background-> White, ImagePadding -> 20];
{},
Grid[{
{Control[{{y, N#Pi/2, "y"}, -Pi, Pi, Appearance -> "Labeled"}]},
{Dynamic#p}
}],
ControlPlacement -> Left,
Alignment -> Center,
ImageMargins -> 1,
FrameMargins -> 1,
ContentSize -> {0}
]
The problem is that M adds a scroll bar automatically:
The help says
If ContentSize specifies a content area that does not completely fit
the contents, then unless specified otherwise with AppearanceElements,
functions like Manipulate display a resize area, as well as scrollbars
when necessary.
The question is, how to use AppearanceElements to remove this scrollbar?
(I wish sometimes that M help is not so short and brief when explaining something).
In the above, notice it says: unless specified otherwise with AppearanceElements,
but I was not able to find out what this means. What does 'otherwise' is
supposed to mean?
The closest I got is by adding AppearanceElements -> "" to the above. So the new
version now becomes
Manipulate[
p = Framed#
Plot[Sin[x], {x, -y, y}, ImageSize -> 300, Background -> White,
ImagePadding -> 20];
{},
Grid[{
{Control[{{y, N#Pi/2, "y"}, -Pi, Pi, Appearance -> "Labeled"}]},
{Dynamic#p}
}],
ControlPlacement -> Left,
Alignment -> Center,
ImageMargins -> 1,
FrameMargins -> 1,
ContentSize -> {0},
AppearanceElements -> "" (*added this *)
]
But notice that the size is not quite correct to the right still, it should be more tight,
and I also lost the '+' that used to be there. I have to keep that.
So, I think what I need is just to find what the element name for '+' is, so I can use
the correct AppearanceElements -> "correctNameHere" and I am hoping that this
will do the right thing. (I tried "Close" but that did not do it, I lost the '+' as well)
I just could not find what that '+' element name is. Any one knows?
Here are the places to find more information on this:
http://reference.wolfram.com/mathematica/ref/Manipulator.html
http://reference.wolfram.com/mathematica/ref/ContentSize.html
So, the question is: How to completely remove the scrollbar effect shown
above, but at the same time keep the '+' in the top right corner.
thanks
Update 2
Thanks to the answers below, here is a screen shot of the result.
Manipulate[
p = Framed#
Plot[Sin[x], {x, -y, y}, ImageSize -> 300, Background -> White,
ImagePadding -> 20];
{}, Grid[{{Control[{{y, N#Pi/2, "y"}, -Pi, Pi,
Appearance -> "Labeled"}]}, {Dynamic#p}}],
AppearanceElements -> "BookmarksButton", ControlPlacement -> Left,
Alignment -> Center, ImageMargins -> 1, FrameMargins -> 1,
ContentSize -> {0}, Alignment -> Center]
I am happy with it. The small white line showing at the top corner seems to
be a side-effect of this. Will have to live it I guess.
Manipulate[
p = Framed#
Plot[Sin[x], {x, -y, y}, ImageSize -> 300, Background -> White,
ImagePadding -> 20];
{}, Grid[{{Control[{{y, N#Pi/2, "y"}, -Pi, Pi,
Appearance -> "Labeled"}]}, {Dynamic#p}}]
, AppearanceElements -> "ManipulateMenu", ControlPlacement -> Left,
Alignment -> Center, ImageMargins -> 1, FrameMargins -> 0,
ContentSize -> {0} ]
Setting FrameMargins->0 gets rid of white lines (on a Mac anyway) but still leaves the Frame lines there. Frame->False doesn't change this. It appears that Manipulate wants to draw a content area no matter what. The AppearanceElements option seems to be incompletely/poorly documented. The following are valid options, though there may be others I do not know of:
{"ContentResizeArea", "HideControlsButton", "ManipulateMenu", "SnapshotButton",
"ResetButton", "UpdateButton", "BookmarksButton", All, None}
AppearanceElements -> "BookmarksButton" is what you are looking for. Other AppearanceElementsfor Manipulate in the documentation (ref/Manipulate) are {"HideControlsButton", "SnapshotButton", "ResetButton",
"UpdateButton", All}
Adding Paneled->False as an option to Manipulate gets rid of the white frame. By wrapping Manipulate with Panel you get something that looks like what you need:
Manipulate[ p = Framed#Plot[Sin[x], {x, -y, y}, ImageSize -> 300,
Background -> White, ImagePadding -> 20]; {},
Grid[{{Control[{{y, N#Pi/2, "y"}, -Pi, Pi,
Appearance -> "Labeled"}]}, {Dynamic#p}}],
AppearanceElements -> "BookmarksButton", ControlPlacement -> Left,
Alignment -> Center, ImageMargins -> 1, FrameMargins -> 0,
ContentSize -> {0}, Paneled->False ]//Panel

Style dynamic value

Can I apply Style to the output of "Labeled" in the below ?
Manipulate[\[Lambda],
Control#{{\[Lambda], 401,
Style[" \[Lambda]", Black, Bold, 24]},
Range[401, 570, 1],
ControlType -> Slider,
ControlPlacement -> Bottom,
Appearance -> "Labeled",
ImageSize -> 200}]
That is on the right part of the Slider :
You want the option BaseStyle (which appears in Options[Slider]). E.g.
Manipulate[
Plot[Cos[k x], {x, 0, 2 Pi}, PlotLabel -> "Cosine"],
{{k, 1, Style["x", Black, Bold, 24]}, 0, 4,
ControlType -> Slider, Appearance -> "Labeled",
ControlPlacement -> Bottom, ImageSize -> 200,
BaseStyle -> {Red, Large, Italic, FontFamily -> "Times"}}]
When looking at this I noticed that you can also use the almost undocumented ControlType -> LabeledSlider, just for something different.
It seems to be at least partially affected by LabelStyle and BaseStyle. (I'm having trouble changing the font, for some reason, but size, weight, color seem to work fine.)

GridLine on top of a Bar Chart in Mathematica

Is it possible to get a GridLine over a BartChart ?
Gridlines draw it under and Mesh does not seem to work with BarChart.
BarChart[{Range[10], Range[10]},
ChartLayout -> "Stacked",
GridLines -> {None, {4}},
GridLinesStyle -> Directive[Orange, Thick]]
This can be done via a method option:
BarChart[{Range[10], Range[10]}, ChartLayout -> "Stacked",
GridLines -> {None, {4}}, GridLinesStyle -> Directive[Orange, Thick],
Method -> {"GridLinesInFront" -> True}]
(this should work for any graphic.)
Your other option would be to draw the gridline explicitly with Epilog. This would be the solution if you wanted some gridlines (e.g. vertical ones) behind and some in front.
I have added some other options in case you don't actually want the gridline to bleed over the axes.
BarChart[{Range[10], Range[10]}, ChartLayout -> "Stacked",
Epilog -> {Orange, Thick, Line[{{0, 4}, {3, 4}}]},
PlotRangeClipping -> True, PlotRangePadding -> 0]

Getting coordinates of manually drawn points

I have a graph as a result of executing ListPlot[] function.
I can manually edit this graph by moving points to a different location
and also adding new points using the Drawing Tools.
How do I get the coordinates of new and changed points from the edited graphics?
I'm not sure if the following is anything like what you want,but nevertheless:
If I use ListPlot as follows:
lp1 = Labeled[
ListPlot[Diagonal#Table[{x, y}, {x, 0, 5}, {y, 5}],
PlotStyle -> {Directive[Red, PointSize[Large]]}], "lp1"];
By double clicking on one of the red points twice to get the selection to the level of the points, I can then move the individual points, e.g., to make the points lie on a curve (rather than a straight line). I now want to extract these points (and say use them in a new ListPlot) [see plots below]
If I click on the bracket of the plot graphic and use "Show Expression" (Command Shift E on a Mac), I can 'see' the coordinates of the modified points which may then be extracted. For example:
expr = Cell[
BoxData[GraphicsBox[{RGBColor[1, 0, 0], PointSize[Large],
PointBox[{{0., 1.}, {0.8254488458250212,
2.886651181634783}, {1.9301795383300084`,
3.925201233010209}, {3.046546974446661,
4.597525796319094}, {4., 5.}}]},
AspectRatio -> NCache[GoldenRatio^(-1), 0.6180339887498948],
Axes -> True, PlotRange -> Automatic,
PlotRangeClipping -> True]], "Input",
CellChangeTimes -> {{3.504427833788156*^9, 3.50442786823486*^9}}];
Modifying a very useful approach originally suggested by Yaroslav Bulatov, which may be found here
modpoints = Flatten[Cases[expr, PointBox[___], Infinity][[All, 1]], {{2, 1}}]
EDIT
As pointed out by belisarius, it is desirable to be able to extract 'manually' added points (which may be added to the generated plot using 'point' from the Drawing Tools palette). A better way of extracting (after 'Show Expression' ...) is probably the following:
modpoints = Cases[Cases[expr, PointBox[___],
Infinity], {_?NumericQ, _?NumericQ}, Infinity]
Of course, 'Show Expression' is not the only approach.
InputForm is another possibility. For example,
expr2 = InputForm[ListPlotGraphic]
modpoints = Cases[Cases[expr, Point[___],
Infinity], {_?NumericQ, _?NumericQ}, Infinity]
where "ListPlotGraphic" is the modified graphic (inserted by 'copy and paste'), will also work.
Example plots
Addendum
The above can be automated with a little notebook programming:
lp1 = Labeled[
ListPlot[Diagonal#Table[{x, y}, {x, 0, 5}, {y, 5}],
PlotStyle -> {Directive[Red, PointSize[Large]]}],
Button["Print points",
With[{nb = ButtonNotebook[]},
SelectionMove[nb, All, CellContents];
Print[Cases[NotebookRead[nb],
PointBox[{{_?NumericQ, _?NumericQ} ..}] |
PointBox[{_?NumericQ, _?NumericQ}], Infinity]]]]]
Running the above, moving the last two original (red) points and adding a couple of extra points in blue with the drawing tools then pressing the button yields
You can see that there is a single PointBox for the original data and a new PointBox for each of the added points. Of course, by modifying the above code, you can do more than simply print out the raw point coordinates.
This approach makes every data point a locator that can be moved. New locators can be added and old ones deleted as appropriate. The best fit and variance are updated after every change.
Here's some data of some exponential growth with some errors and a data point missing
data = Delete[Table[{t, (1 + RandomReal[{-.2, .2}])Exp[t]}, {t, 0, 2, .2}], 6];
A little formatting command:
nForm = NumberForm[#, {2, 2}, NumberPadding -> {"", "0"}] &;
Finally, here's the code to make the manipulable graphics. New locators/data points are added using Alt-Click (or Ctrl-Alt-Click on linux). If you click on the list of points on the left, then a new window is opened containing the points in input form.
Manipulate[
LocatorPane[Dynamic[pts, {None, Temporary, Automatic}],
nlm = Block[{a,b,t}, NonlinearModelFit[Sort[pts], a Exp[t] + b, {a, b}, t]];
Show[Plot[{Exp[t], nlm[t]}, {t, 0, 2},
PlotStyle -> {{Thick, LightGray}, Dotted}, PlotRangePadding -> Scaled[0.1]],
ListPlot[data, PlotStyle -> Blue], AxesLabel -> Block[{t,f}, {t, f[t]}]],
LocatorAutoCreate -> True, Appearance -> Style["\[CircleDot]", Red]],
{nlm, None}, {{pts, data}, None},
Dynamic[Pane[EventHandler[
nForm#Grid[Prepend[pts, {"x", "y"}], Dividers -> {False, 2 -> True}],
{"MouseClicked" :> (CreateDocument[{ExpressionCell[nlm["Data"], "Output"]},
WindowTitle -> "Data"])}], ImageSize -> {100, 250},
ImageSizeAction -> "Scrollable", Scrollbars -> {False, True}]],
Pane[Dynamic[nForm#Row#{nlm,Row[{"\tvariance = ",nlm["EstimatedVariance"]}]}]],
ControlPlacement -> {Left, Left, Left, Top}]
In the above I've used the locators to correct a couple of outliers and restored the missing data point.
The easy option is to use the "Get Coordinates" menu option. If you right click on the graphic, in the pop-up menu you'll see "Get Coordinates" which allows you to mouse-over a point and see that point's coordinates. Of course this isn't going to be accurate... but the way you're editing the graphic isn't very accurate either.
You could use the InputForm (or FullForm) function, but I am not sure how well this works...
In[1]:= a = ListPlot[{{1, 0}, {0, 1}, {1, 1}}];
a // InputForm
Out[2]//InputForm=
Graphics[{{{}, {Hue[0.67, 0.6, 0.6], Point[{{1., 0.}, {0., 1.}, {1., 1.}}]},
{}}}, {AspectRatio -> GoldenRatio^(-1), Axes -> True, AxesOrigin -> {0, 0},
PlotRange -> {{0., 1.}, {0., 1.}}, PlotRangeClipping -> True,
PlotRangePadding -> {Scaled[0.02], Scaled[0.02]}}]
You'll notice that there's a Point expression in there.
The third option would be to use Locator in some way I guess.

Resources