I have an annoying problem using GraphicsColumn() in Mathematica to combine several DateList plots in a single column. I need them to be correctly aligned as they display different timeseries for the same period, but as it turns out the size of the frame of each plot gets automatically resized depending on the length of the Y-axis labels. So combining a plot with 5-figure labels and one with 2-figure labels will totally jeopardise the vertical alignment. I tried several tweaks (e.g. setting width or max width via ImageSize), unfortunately they all seem to apply to the size of the graphic as a whole, not the actual frame. I don't seem to find a way to control the size of the frame itself. Any ideas?
I suspect you want to set the ImagePadding option:
GraphicsColumn[{
Plot[Sin[x], {x, 0, 2 Pi}, ImagePadding -> 20, AxesLabel -> {"x", "very very loooooooong"}],
Plot[Sin[x], {x, 0, 2 Pi}, ImagePadding -> 20, AxesLabel -> {"x", "shrt"}]
}]
I am not sure how you are labeling the graph, but this method should work if you set the value high enough to show the whole label.
You could try the the LevelScheme Multipanel command.
Here's the example given in their documentation and LevelSchemeExamples.nb:
Figure[
{ScaledLabel[{0.5, 1}, "Lissajous curves", FontSize -> 18, Offset -> {0, 1}],
Multipanel[{{0, 1}, {0, 1}}, {2, 2},
XPlotRanges -> {{-1.5, 1.5}, {-Pi/2, 8*Pi + Pi/2}},
YPlotRanges -> {-1.5, 1.5},
XFrameLabels -> {textit["x"], textit["t"]}, BufferB -> 2.5,
YFrameLabels -> textit["y"], BufferL -> 3,
TickFontSize -> 10,
XFrameTicks -> {LinTicks[-2, 2, 1, 5], LinTicks[-Pi, 9*Pi, Pi, 4,
TickLabelFunction -> (Rationalize[#/Pi]*Pi &)]},
YFrameTicks -> LinTicks[-2, 2, 1, 5],
XPanelSizes -> {1, 2.5}, XGapSizes -> {0.1},
YPanelSizes -> {1, 1}, YGapSizes -> {0.1},
Background -> Wheat, PanelLetterBackground -> Wheat
],
FigurePanel[{1, 1}],
RawGraphics[ParametricPlot[{Cos[1*t], Cos[1*t - Pi/2]}, {t, 0, 2*Pi}]],
FigurePanel[{1, 2}],
RawGraphics[Plot[Cos[1*t], {t, 0, 8*Pi}], Dashing -> Automatic],
RawGraphics[Plot[Cos[1*t - Pi/2], {t, 0, 8*Pi}]],
FigurePanel[{2, 1}, PanelLetterBackground -> None],
RawGraphics[ParametricPlot[{Cos[1*t], Cos[4*t - Pi/2]}, {t, 0, 2*Pi}]],
FigurePanel[{2, 2}],
RawGraphics[Plot[Cos[1*t], {t, 0, 8*Pi}], Dashing -> Automatic],
RawGraphics[Plot[Cos[4*t - Pi/2], {t, 0, 8*Pi}]],
},
PlotRange -> {{-0.1, 1.1}, {-0.1, 1.1}},
ImageSize -> 72*2*{3.6, 2.1}
]
Related
I am very new to Mathematica. I have version 11, if that makes a difference.
I am trying to take the area formed by the following lines and and revolve it to form a 3D solid.
y = e^-x
Here is my code, in two sections
f[x_] := E^-x
g[x_] := 1
Plot[{f[x], g[x]}, {x, 0, 2}, Filling -> {1 -> {2}},
PlotLegends -> {"f[x]", "g[x]", "h[y]"}]
Next:
RevolutionPlot3D[(1 - f[x]) , {x, 0, 2}, RevolutionAxis -> "X"]
Here is the 2D and 3D representations:
The 2D one is correct, but not the 3D. I want to rotate the area about y=2 (horizontal line) as to form a shape with a hole in the center. I don't know how to set the axis of rotation to anything other than an axis line. I just want y=2.
How do you accomplish this?
RevolutionPlot3D isn't the right tool for what you want for 2 reasons. First, you want to rotate a 2D region not a line. Second, you want to rotate around a line that isn't one of the axes. RegionPlot3D is the built-in tool for the job. You can easily set up your region as a boolean region, just think about the conditions that the radius x^2 + y^2 has to satisfy
RegionPlot3D[
1 < z^2 + y^2 < (2 - Exp[-x])^2, {x, 0, 2}, {y, -3, 3}, {z, -3, 3}]
I showed the result from 2 different angles to point out the shortcomings of RegionPlot3D. You could improve this result by using a high value for the PlotPoints option, but it isn't great. That's why you should use Simon Woods's function contourRegionPlot3D, defined in this post:
contourRegionPlot3D[
1 < z^2 + y^2 < (2 - Exp[-x])^2, {x, 0, 2}, {y, -3, 3}, {z, -3, 3}]
How could I create the following using Rectangle[] in Graphics[]?
Using Polygon, you can
Graphics[{EdgeForm[Black],
Polygon[{{0, 0}, {3, 0}, {3, 1}, {0, 1}},
VertexColors -> {White, Red, Red, White}]}]
Also:
Graphics[Raster[{Range[100]/100}, ColorFunction -> (Blend[{White, Red}, #] &)],
AspectRatio -> .3,
Frame -> True,
FrameTicks -> None]
Please consider :
Manipulate[
Row[{
Graphics[Disk[]],
Graphics[{
Polygon[{{0, 0}, {3, 0}, {3, 1}, {0, 1}},
VertexColors -> {White, Blend[{White, Blue}],
Blend[{White, Blue}], White}],
Black, Thick,
Line[{{i, 0}, {i, 1}}]}, ImageSize -> 300]}],
{i, 0, 3}]
Using Szabolcs`s solution on Gradient Filling
How could I color the disk with the color located underneath the Black Line ?
Here is one solution which works because the color on the left is White and the gradient is linear.
With[{max = 3, color = Blend[{White, Blue}]},
Manipulate[
Row[{Graphics[{Opacity[i/max], color, Disk[]}],
Graphics[{Polygon[{{0, 0}, {max, 0}, {max, 1}, {0, 1}},
VertexColors -> {White, color, color, White}], Black, Thick,
Line[{{i, 0}, {i, 1}}]}, ImageSize -> 300]}], {i, 0, max}]]
If you had two different colors for each end (i.e., something other than White), the Opacity approach won't work. Instead, you can use the optional blending fraction argument to Blend the colors in the desired proportion. Here's an example:
With[{max = 3, color1 = Red, color2 = Green},
Manipulate[
Row[{Graphics[{Blend[{color1, color2}, i/max], Disk[]}],
Graphics[{Polygon[{{0, 0}, {max, 0}, {max, 1}, {0, 1}},
VertexColors -> {color1, color2, color2, color1}], Black,
Thick, Line[{{i, 0}, {i, 1}}]}, ImageSize -> 300]}], {i, 0,
max}]]
If you need to do this for a blend of colours other than something and white, Opacity won't be suitable. You could instead stay closer to Szabolcs' original solution using the second argument to Blend like so:
skyBlue = Blend[{White,Blue}];
Manipulate[ Row[{ Graphics[{Blend[{White,skyBlue},i/3], Disk[]}],
Graphics[{ Polygon[{{0, 0}, {3, 0}, {3, 1}, {0, 1}},
VertexColors -> {White, skyBlue,
skyBlue, White}], Black, Thick,
Line[{{i, 0}, {i, 1}}]}, ImageSize -> 300]}], {i, 0, 3}]
I have divided i by 3 because that parameter is meant to vary between 0 and 1.
Given two vector plots and a contour plot like the following
as = VectorPlot[{Cos[y], Sin[x] }, {x, -3, 3}, {y, -3, 3},
VectorScale -> Automatic, VectorColorFunction -> "Rainbow"
];
bs = StreamPlot[{Cos[y], Sin[x] }, {x, -3, 3}, {y, -3, 3},
VectorScale -> Automatic, StreamColorFunction -> "Rainbow"
];
cs = ContourPlot[Cos[x] + Sin[y], {x, -3, 3}, {y, -3, 3},
ColorFunction -> "BlueGreenYellow"
];
Show[cs, bs, as]
we can see basic superimposing job is well done by Show[]. But my question is how can I control the opacity of the background contour plot cs? Also, how can I insert "BlueGreenYellow" type color schemes in a color function like the following?
ContourPlot[Cos[x] + Sin[y], {x, -3, 3}, {y, -3, 3},
ColorFunction -> (Directive[Opacity[#],Blue] &)
];
I do not believe that jmlopez' solution is correct, because the vectors and the frame are also partially transparent. I believe that it is better to insert an Opacity command into the Graphics object, which will preserve opaque vectors:
as = VectorPlot[{Cos[y], Sin[x]}, {x, -3, 3}, {y, -3, 3},
VectorScale -> Automatic, VectorColorFunction -> "Rainbow"];
bs = StreamPlot[{Cos[y], Sin[x]}, {x, -3, 3}, {y, -3, 3},
VectorScale -> Automatic, StreamColorFunction -> "Rainbow"];
cs = ContourPlot[Cos[x] + Sin[y], {x, -3, 3}, {y, -3, 3},
ColorFunction -> "BlueGreenYellow"];
cs2 = MapAt[{Opacity[0.5], #} &, cs, 1];
Show[cs2, bs, as]
The second question was never addressed. You can combine opacity and a color gradient like this:
ContourPlot[Cos[x] + Sin[y], {x, -3, 3}, {y, -3, 3},
ColorFunction -> ({Opacity[#], ColorData["BlueGreenYellow"][#]} &)
]
You can try using BaseStyle as follows:
cs = ContourPlot[Cos[x] + Sin[y], {x, -3, 3}, {y, -3, 3},
ColorFunction -> "BlueGreenYellow",
BaseStyle -> Directive[Opacity[0.5]]
];
Considering :
preferred ={{1, 1, 63}, {2, 1, 44}, {3, 1, 27}, {4, 1, 33}, {5, 1, 33}}
frmWidth = 20.9067;
frmHeight = 15.68;
I am displaying 5 types of stimuli 2 by 2. Subjects must choose the one they prefer. Each type of stimuli is displayed 80 times so :
{1,1,63} indicates that the stimuli Cond 1 was preferred 63 times out of the 80 times it was displayed.
{3, 1, 27} indicates that the stimuli Cond 3 was preferred 27 times out of the 80 times it was displayed.
Cond1 refers to center of the screen
Cond2 refers to Top-Left Quadrant
Cond3 refers to Top-Right Quadrant
Cond4 refers to Bottom-Left Quadrant
Cond5 refers to Bottom-Right Quadrant
I would like to express this showing results.
This is what I have done :
Graphics[{
Black, EdgeForm[{Thin, LightGray}],
Rectangle[{-1, -1}, {frmWidth + 1, frmHeight + 1}],
PointSize[0.03],
Yellow,
Point#Tuples[{Range[0, frmWidth/2, frmWidth/19],
Range[0, frmHeight/2, frmHeight/14]}][[;; preferred[[5, 3]]]],
Red,
Point#Tuples[{Range[frmWidth/2, frmWidth, frmWidth/19],
Range[0, frmHeight/2, frmHeight/14]}][[;; preferred[[4, 3]]]],
Green,
Point#Tuples[{Range[frmWidth/2, frmWidth, frmWidth/19],
Range[frmHeight/2, frmHeight, frmHeight/14]}][[;; preferred[[3, 3]]]],
Orange,
Point#Tuples[{Range[0, frmWidth/2, frmWidth/19],
Range[frmHeight/2, frmHeight, frmHeight/14]}][[;;
preferred[[2, 3]]]],
Blue,
Point#Tuples[{Range[frmWidth/4, 3/4 frmWidth, frmWidth/19],
Range[frmHeight/4, 3/4 frmHeight, frmHeight/14]}][[;;
preferred[[1, 3]]]]
}]
Problem is the rectangles are gradually filled with points from left to right, instead of the points being uniformly located.
Consider the following :
Graphics[{
White, EdgeForm[Thick],
Rectangle[{0, 0}, {frmWidth, frmHeight}],
Orange, Opacity[.5],
Rectangle[{0, frmHeight/2}, {frmWidth/2, frmHeight}, RoundingRadius -> 3],
Green,
Rectangle[{frmWidth/2, frmHeight/2}, {frmWidth, frmHeight},RoundingRadius -> 3],
Red,
Rectangle[{frmWidth/2, 0}, {frmWidth, frmHeight/2}, RoundingRadius -> 3],
Yellow,
Rectangle[{0, 0}, {frmWidth/2, frmHeight/2}, RoundingRadius -> 3],
Blue,
Rectangle[{frmWidth/4, frmHeight/4}, {3/4 frmWidth, 3/4 frmHeight}, RoundingRadius -> 3]
}]
Now I would like to fill those edge rounded rectangles with the points but have the density changing rather than the part of the rectangles that are filled.
Below is something very ugly I draw in PPT :
Ideally, the shapes filled with Points could be of any kind.
Points would not overlap.
Please let me know alternative ideas.
OK, try this:
Manipulate[ld = Floor[Sqrt[n]];
Graphics[
{{EdgeForm[Dashed], White,
Polygon[{{0, 0}, {0, h}, {w, h}, {w, 0}}]},
Point[Flatten[#, 1] &#
Table[{x, y}, {x, 0, w, w/ld}, {y, 0, h, h/ld}]] },
PlotRange \[Rule] {{-1, 20}, {-1, 20}}],
{{n, 25}, 10, 100, 1},
{{h, 10}, 5, 20},
{{w, 10}, 5, 20}]
typical configuration:
(the code I gave lets you control the total number and size of the box via sliders)
Given that your rectangles are rather small, the easiest solution is to use
RandomSample[ allPointsInAnObject ]
Kind of like so:
Graphics[{Circle[{0, 0}, 11], PointSize[0.02],
Point[RandomSample[
Cases[Outer[List, Range[-11, 11], Range[-11, 11]], {x_, y_} /;
x^2 + y^2 <= 11^2, {2}], 50]]}]