Changing Plot Color in Mathematica

In summary, the conversation discussed how to generate a specific plot in Mathematica and change its color to red. The correct code was provided, which involved using the ParametricPlot function and specifying the desired color using either RGB values or the color name directly. An image of the final plot was also shared.
  • #1
roam
1,271
12
I want to generate the following plot in Mathematica in red color:

Code:
x[t_] := 31 Cos[t] - 7 Cos[31 t/7];
y[t_] := 31 Sin[t] - 7 Sin[31 t/7];
ParametricPlot[{x[t], y[t]}, {t, 0, 19 \[Pi]}]

The above code creates the plot in default black color. So, I tried using this code to make it red:

Code:
x[t_] := 31 Cos[t] - 7 Cos[31 t/7];
y[t_] := 31 Sin[t] - 7 Sin[31 t/7];
ParametricPlot[[{x[t], y[t]}, {t, 0, 19 \[Pi]}],
PlotStyle -> {{RGBColor[1,0,0]}}]

Unfortunently it doesn't work and I get errors. Can anybody help with this?
 
Physics news on Phys.org
  • #2
You've got too many braces! Here's the working code:

Code:
x[t_] := 31 Cos[t] - 7 Cos[31 t/7];
y[t_] := 31 Sin[t] - 7 Sin[31 t/7];
ParametricPlot[{x[t], y[t]}, {t, 0, 19 \[Pi]}, 
 PlotStyle -> {RGBColor[1, 0, 0]}]

Alternatively, you can just pass the name of the color directly to PlotStyle:

Code:
x[t_] := 31 Cos[t] - 7 Cos[31 t/7];
y[t_] := 31 Sin[t] - 7 Sin[31 t/7];
ParametricPlot[{x[t], y[t]}, {t, 0, 19 \[Pi]}, 
 PlotStyle -> {Red}]

http://img39.imageshack.us/img39/7893/64328066.jpg
 
Last edited by a moderator:
  • #3


I understand your frustration with trying to change the plot color in Mathematica. It can be a bit tricky, but there are a few different ways to achieve the desired result.

One option is to use the PlotStyle option within the ParametricPlot function. This allows you to specify the color and other styling options for the plot. In your case, you could use the RGBColor function to create a red color and apply it to the plot as follows:

ParametricPlot[{x[t], y[t]}, {t, 0, 19 \[Pi]}, PlotStyle -> RGBColor[1, 0, 0]]

Another option is to use the ColorFunction option within ParametricPlot. This allows you to specify a function that will determine the color of each point in the plot based on its coordinates. For example, you could use the following code to create a plot with a color gradient from red to blue:

ParametricPlot[{x[t], y[t]}, {t, 0, 19 \[Pi]}, ColorFunction -> (Blend[{Red, Blue}, #] &)]

I hope this helps you achieve the desired red plot in Mathematica. If you continue to experience errors, it may be helpful to consult the Mathematica documentation or seek assistance from other Mathematica users online.
 

1. How do I change the plot color in Mathematica?

To change the plot color in Mathematica, you can use the PlotStyle option and specify the desired color or use the ColorFunction option to assign colors based on a function. You can also use the Graphics command to create custom graphics with specific colors.

2. Can I change the color of individual data points in a plot?

Yes, you can change the color of individual data points in a plot by using the PlotMarkers option and specifying a color for each data point. You can also use the Show command to combine multiple plots with different colored data points.

3. How do I create a color gradient in a plot?

To create a color gradient in a plot, you can use the ColorFunction option and specify a color gradient function such as Hue, Blend, or RGBColor. You can also use the ColorFunctionScaling option to adjust the scaling of the color gradient.

4. Is it possible to change the color of a specific curve in a multi-curve plot?

Yes, you can change the color of a specific curve in a multi-curve plot by using the PlotStyle option and specifying a different color for that particular curve. You can also use the PlotLegends option to create a legend and assign colors to each curve.

5. How do I change the default plot colors in Mathematica?

To change the default plot colors in Mathematica, you can use the PlotTheme option and choose a pre-defined theme or create a custom theme with specific color choices. You can also use the DefaultAxesStyle option to change the default colors for axes and labels.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
246
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
211
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
886
Back
Top