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]
Related
I have a data set with x,y and error(y) values. I write this in mathematica as:
Needs["ErrorBarPlots`"]
data = {{{0, 0.10981309359605919},
ErrorBar[0.05240427422664753`]}, {{0.2145, 0.09146326059113304},
ErrorBar[0.034195343626358385`]}, {{0.4290, 0.08230438177339898},
ErrorBar[0.02533205817067696`]}, {{0.6435, 0.0768141842364532},
ErrorBar[0.020205473852635995`]}, {{0.8580, 0.07223473349753692},
ErrorBar[0.016156209168991867`]}, {{4, 0.056122650246305375},
ErrorBar[0.009288720442961331]}};
ErrorListPlot[data, Frame -> True, FrameStyle -> Directive[Black, 20],
PlotRange -> {{-0.1, 5}, {0.2, 0}}, Axes -> False,
PlotStyle -> {Directive[Red, 12], AbsolutePointSize[10],
AbsoluteThickness[3]} , LabelStyle -> Directive[Green],
BaseStyle -> {Large, FontFamily -> "Courier", FontSize -> 12}]
But what I am trying to obtain is draw a line and get a shaded error band connecting the errorbars which obey a functional form, f(x)= 0.05 + 0.02/(x^2 + 0.425) . I don't want to show the error bars explicitly , rather I want to show the band. I am looking for something like this
I have looked at this link http://reference.wolfram.com/language/howto/GetResultsForFittedModels.html
but couldn't solve the problem. Could anyone please help me? Thanks.
Here is one approach, make two lists, one list for upper range of the erros:
dataPLUS = {{0, 0.10981309359605919 + 0.05240427422664753`}, {0.2145,
0.09146326059113304 + 0.034195343626358385`}, {0.4290,
0.08230438177339898 + 0.02533205817067696`}, {0.6435,
0.0768141842364532 + 0.020205473852635995`}, {0.8580,
0.07223473349753692 + 0.016156209168991867`}, {4,
0.056122650246305375 + 0.009288720442961331}};
another list for the lower range of the errors as:
dataMINUS = {{0, 0.10981309359605919 - 0.05240427422664753`}, {0.2145,
0.09146326059113304 - 0.034195343626358385`}, {0.4290,
0.08230438177339898 - 0.02533205817067696`}, {0.6435,
0.0768141842364532 - 0.020205473852635995`}, {0.8580,
0.07223473349753692 - 0.016156209168991867`}, {4,
0.056122650246305375 - 0.009288720442961331}};
Once you have the two sets you can use the ListPlot option as:
ListPlot[{dataPLUS, dataMINUS}, PlotStyle -> Red, PlotRange -> All]
which will generate a graph like
if you want to join them, instead use ListLinePlot option
ListLinePlot[{dataPLUS, dataMINUS}, PlotStyle -> Red,PlotRange -> All]
and to have a shaded region in between, use the Filling option
ListLinePlot[{dataPLUS, dataMINUS}, PlotStyle -> Red, Filling -> {1 -> {{2}, Gray}}, PlotRange -> All]
To get smooth graph, you need more data points. Hope this will help.
And to include the BestFit line, define a function and add to the previous plots as:
f[x_] = 0.05 + 0.02/(x^2 + 0.425);
plot2 = Plot[f[x], {x, 0, 5}, PlotStyle -> {Red, Thick}];
plot1 = ListLinePlot[{dataPLUS, dataMINUS}, PlotStyle -> LightGray,Filling -> {1 -> {{2}, LightGray}}, PlotRange -> All];
Show[{plot1, plot2}]
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/
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
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.)
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]