Why does the following code
Graphics[Raster[{{Hue[1], Hue[1/3]}, {Hue[2/3], Hue[1/6]}}]]
not produce any output? In Mathematica < 6 RasterArray was able to handle this and produced the same output as
Graphics[Raster[{{{1, 0, 0}, {0, 1, 0}}, {{0, 0, 1}, {1, 1, 0}}}]]
The documentation of Raster indicates that its arguments are not graphics directives (e.g. Hue, RGBColor) but rather numbers - a gray level (single number), RGB values (three numbers), RGBalpha values (four numbers), or gray-alpha values (two numbers). However, it provides the ability to instead specify the color function yourself, for example:
Graphics[Raster[{{0, 0.2, 0.4}, {0.6, 0.8, 1}}, ColorFunction -> Hue]]
(straight from the documentation for v6)
Related
I want to get a continuous square wave use the software mathematica.
Plot[SquareWave[{0, 10}, x], {x, 0, 10},
ExclusionsStyle -> Directive[Dotted, Red]]
However, if I set the xmax to be 100,the picture will be out of expectation.
Plot[SquareWave[{0, 10}, x], {x, 0, 100},
ExclusionsStyle -> Directive[Dotted, Red]]
Here is the result:
(http://i.stack.imgur.com/NfWVK.png)
What about another way to generate a square wave? I didn't remember where I saw,but I know we can use UnitStep.
However, it still exists the problem out of expectation.
Plot[10 UnitStep[-Sin[0.4 Pi t]], {t, 0, 200}, Exclusions -> None,
PlotStyle -> Thick]
Plot[10 UnitStep[-Sin[0.4 Pi t]], {t, 0, 500}, Exclusions -> None,
PlotStyle -> Thick]
(http://i.stack.imgur.com/iPRLc.png)
Actually,the square wave generate is used as the clock signal, so I hope it stable, continuous.
Hope you could help me to slove this problem. Hear from you soon.
There is nothing wrong with SquareWave. The trouble is Plot does a fairly coarse initial sampling and doesn't detect all the discrete regions. You simply need to give Plot a PlotPoints specification:
Plot[SquareWave[{0, 10}, x], {x, 0, 100}, PlotPoints -> 1000,
ExclusionsStyle -> Directive[Dotted, Red]]
PlotPoints needs to be set large enough so that the initial sampling hits every interval.
Alternately you can explicitly provide the points to plot and use ListLinePlot
ListLinePlot[
Flatten[Table[
{{i,10},{i+1,10},{i+1,0},{i+2,0}} ,
{i, 0, 100, 2}], 1]]
I don't see straight away how to apply the dashing in this case though.
I have a ListPointPlot3D containing four series of data. I would like to be able to define the size, shape and colour of these series individually. Changing the size and colour is crucial, the shape not so much.
The Mathematica documentation is unhelpful for the 3D case, but for 2D plots I managed to get things to work perfectly.
Can anyone advise how best to do this in 3D?,
Thanks
Make up some data:
Table[data[k] =
Table[3 k + Sin[j^2 + i], {i, -Pi, Pi, 0.2}, {j, -2, 2, 0.2}], {k, 4}];
Apply different styles via PlotStyle and Directive to different data sets:
ListPointPlot3D[{data[1], data[2], data[3], data[4]},
PlotStyle -> {
Directive[Opacity[.5], Red, PointSize[.005]],
Directive[Opacity[.5], Blue, PointSize[.01]],
Directive[Opacity[.5], Green, PointSize[.015]],
Directive[Opacity[.5], Black, PointSize[.02]]
}, BoxRatios -> 1]
How can I replace the pixels of a binarized image with a custom image in Mathematica?
I figured that once I have a matrix M of 0 or 1 entries depending on a pixel being white or black (which I can obtain by using Binarize and manipulating the output a bit), I can use Graphics[] to place a custom image with square boundary in a grid wherever there's a 1 and a flat background when there's a 0, but I'm not exactly sure how to do this.
Thank you in advance :)
Here's one way:
mat = RandomInteger[1, {10, 10}];
Graphics[MapIndexed[If[#1 == 1, Disk, Circle][#2, 0.4] &, mat, {2}]]
I like to use various versions of MapIndexed for this. Instead of Disk or Circle you can use any other graphics object. Just make a function that will take a position as its argument and will produce that object.
If M is your matrix containing 0's and 1's and image0/image1 are the images you want to display:
image0 = Graphics[{Red, Disk[]}, ImageSize -> 10];
image1 = Graphics[{Blue, Rectangle[]}, ImageSize -> 10];
M = {{0, 1, 0}, {1, 1, 1}, {1, 0, 0}};
You can just do this:
GraphicsGrid[M /. {0 -> image0, 1 -> image1}]
or, if you want the 0's to be blank:
GraphicsGrid[M /. {0 -> "", 1 -> image1}]
Please consider :
colors = {Red, Green, Blue};
style = {Thickness[.01], Thickness[.01], Thickness[.01]};
cAxes = {{{0, 0, 0}, {0, 0, 1}}, {{0, 0, 0}, {0, 1, 0}}, {{0, 0,
0}, {1, 0, 0}}};
Graphics3D[{{#1, #2, Line##3} & ### Transpose#{colors, style, cAxes},
Blue, Specularity[White, 3], Sphere[{.5, .5, .5}, .1]},
Boxed -> False, FaceGrids -> All,
FaceGridsStyle -> Directive[Black, Dashed]]
Using Yoda`s solution on How to Style Lines
How could I color the Sphere using GrayLevel (I will manipulate it later).
And How could I have denser FaceGrids ? 10 Lines horizontally & Vertically. I also don`t understand why the Edges one are distant to one another.
It's always good practice to group the graphics object and its styles in a list, in case you need to quickly add another one with different styles. By that, I mean write it as {Blue, Specularity[White, 3], Sphere[{.5, .5, .5}, .1]}. Now you can easily add a GrayLevel term before Sphere and it'll work.
For the FaceGrids, I believe you'll have to manually define the lines at your desired spacing for each face. Here's an example for showing how to do it for one face.
Graphics3D[{{#1, #2, Line##3} & ###
Transpose#{colors, style, cAxes}, {Blue, GrayLevel[0.3], Lighting -> "Neutral",
Specularity[White, 3], Sphere[{.5, .5, .5}, .1]}}, Boxed -> False,
FaceGrids -> {{{0, 0, 1},
Transpose#({#, #} & /# Range[0, 1, 0.1])}},
FaceGridsStyle -> Directive[Black, Dashed]]
The faces are defined as ±1 for the corresponding plane and the other two are zero. So {0,0,1} in my example corresponds to the z=1 plane.
The list supplied to FaceGrids can be easily computed for each face, instead of manually entering them, but I'll leave that to you :)
EDIT:
Since you want a uniform mesh all around, define where you want the grid lines drawn as
gridList = Transpose#({#, #} & /# Range[0, 1, 0.1]);
Then, use the following for FaceGrids:
FaceGrids -> Join ## Table[{RotateLeft[j {0, 0, 1}, i], gridList},
{i, {0, 1, 2}}, {j, {-1, 1}}]
Here's how the result should look like with PlotRangePadding -> None:
In addition to Yoda's response:
Lighting -> "Neutral" will allow grayscale object to show up as gray instead of with various colors.
PlotRangePadding -> None will remove the spaces on the grid lines (depending on the setting for PlotRange.)
Yoda beat me to typing out the FaceGrids setting (see documentation). But here is an alternative.
Instead of setting the FaceGrids setting explicitly, youcould also try setting FrameTicks, since by default the FaceGrids follow these, and then style the FrameTicks to be invisible using Opacity.
Reading this question on importing ColorData from matlab, I was wondering if there is a way to change the range of values over which the ColorFunction is scaled. That was probably not entirely clear, so let me show with a figure from matlab (the same example as in the previous question is used)
The plot on the left is the original, with the ColorData mapped to the data values between -1 and 1. Now, I can easily set it to be mapped to the data values between 0 and 1, the result being that all values less than 0 are assigned blue color (lowest in the colormap). PlotRange is the closest function, and using ClippingStyle in addition to that produces a similar figure. However, it doesn't re-scale the ColorData to map to the plot range.
How can I do this in Mathematica?
BTW, to insert colorbars using Mathematica, you can look at this function
Here's a function applied to a surface:
Plot3D[x + y, {x, -2, 2}, {y, -2, 2},
ColorFunction -> (ColorData["Rainbow", #3] &), Mesh -> {{1}, {1}}]
To look at the top-right corner, with the same color function and scaling, I set ColorFunctionScaling -> False, and manually scale the color function to map the (global) minimum to zero and the maximum to one using Rescale:
Plot3D[x + y, {x, 1, 2}, {y, 1, 2}, ColorFunctionScaling -> False,
ColorFunction -> (ColorData["Rainbow", Rescale[#3, {-4, 4}, {0, 1}]] &)]