How can I change values ​​in radians (pi) for x axis on ListPlot?

Hello,

ListPlot[Sqrt[A[n]^2 + B[n]^2] /. n -> {1, 2, 3, 4, 5, 6, 7, 8}, 
 PlotRange -> {{0*\[Pi], 2*\[Pi]}, Automatic}, Filling -> Axis]

How the x-axis looks now is like when 1 would be pi, 2 would be 2pi, 3 would be 3pi, etc:

ListPlot[Sqrt[A[n]^2 + B[n]^2] /. n -> {1, 2, 3, 4, 5, 6, 7, 8}, 
 PlotRange -> {{0*\[Pi], 3*\[Pi]}, Automatic}, Filling -> Axis, 
 Ticks -> {{0*\[Pi], 1*\[Pi], 2*\[Pi], 3*\[Pi]}, Automatic}]

How can I make the x-axis look like this? Is it possible?

Mathematica 13.2 Notebook file attached.

Thank you.

Entire code:

f5[x_] := \!\(\*
TagBox[GridBox[{
{"\[Piecewise]", GridBox[{
{"1", 
RowBox[{"0", "<", "x", "<", "1"}]},
{"0", 
RowBox[{"1", "<", "x", "<", "2"}]}
},
AllowedDimensions->{2, Automatic},
Editable->True,
GridBoxAlignment->{"Columns" -> {{Left}}, "Rows" -> {{Baseline}}},
GridBoxItemSize->{"Columns" -> {{Automatic}}, "Rows" -> {{1.}}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.84]}, 
Offset[0.27999999999999997`]}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}},
Selectable->True]}
},
GridBoxAlignment->{"Columns" -> {{Left}}, "Rows" -> {{Baseline}}},
GridBoxItemSize->{"Columns" -> {{Automatic}}, "Rows" -> {{1.}}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.35]}, 
Offset[0.27999999999999997`]}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}}],
"Piecewise",
DeleteWithContents->True,
Editable->False,
SelectWithContents->True,
Selectable->False,
StripWrapperBoxes->True]\)
Plot[f5[x], {x, 0, 2.5}, Exclusions -> None];
T = 2 - 0;
A0 = 2/T*\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(-
\*FractionBox[\(T\), \(2\)]\), 
FractionBox[\(T\), \(2\)]]\(f5[x] \[DifferentialD]x\)\) // Simplify;
A[n_] = 2/T*\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(-
\*FractionBox[\(T\), \(2\)]\), 
FractionBox[\(T\), \(2\)]]\(f5[x]*Cos[
\*FractionBox[\(2*\[Pi]*n*x\), \(T\)]] \[DifferentialD]x\)\) // 
   Simplify;
B[n_] = 2/T*\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(-
\*FractionBox[\(T\), \(2\)]\), 
FractionBox[\(T\), \(2\)]]\(f5[x]*Sin[
\*FractionBox[\(2*\[Pi]*n*x\), \(T\)]] \[DifferentialD]x\)\) // 
   Simplify;
s5[k_, x_] := A0/2 + \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(n = 1\), \(k\)]\((A[n]*Cos[
\*FractionBox[\(2*\[Pi]*n*x\), \(T\)]] + B[n]*Sin[
\*FractionBox[\(2*\[Pi]*n*x\), \(T\)]])\)\) // Simplify;
ListPlot[Sqrt[A[n]^2 + B[n]^2] /. n -> {1, 2, 3, 4, 5, 6, 7, 8}, 
 PlotRange -> {{0*\[Pi], 3*\[Pi]}, Automatic}, Filling -> Axis, 
 Ticks -> {{0*\[Pi], 1*\[Pi], 2*\[Pi], 3*\[Pi]}, Automatic}]

Untitled-4.nb (9.86 KB)

Try the option

Ticks -> {{#, # Pi} & /@ Range[8], Automatic}

A simple glance into the documentation would have done it …

Thanks. I did not find such a code for Ticks in the documentation. Or what kind of documentation do you look at?

https://reference.wolfram.com/language/

https://reference.wolfram.com/language/ref/Ticks.html

I think that here it is more about the experience than documentation…

I do not understand this:

{#, # Pi} & /@ Range[8]

I understand Range[8] and how it relates to my code, but that {#, #Pi} and &/@ not yet :

41891.JPG

Now if I want to have on the y-axis something like that:

How can I do this?

ListPlot[{\!\(
\*SubscriptBox[\(\[Limit]\), \(n -> 
\*SuperscriptBox[\(1\), \(+\)]\)]\(ArcTan[
\*FractionBox[\(B[n]\), \(A[n]\)]]\)\), \!\(
\*SubscriptBox[\(\[Limit]\), \(n -> 
\*SuperscriptBox[\(2\), \(+\)]\)]\(ArcTan[
\*FractionBox[\(B[n]\), \(A[n]\)]]\)\), \!\(
\*SubscriptBox[\(\[Limit]\), \(n -> 
\*SuperscriptBox[\(3\), \(+\)]\)]\(ArcTan[
\*FractionBox[\(B[n]\), \(A[n]\)]]\)\), \!\(
\*SubscriptBox[\(\[Limit]\), \(n -> 
\*SuperscriptBox[\(4\), \(+\)]\)]\(ArcTan[
\*FractionBox[\(B[n]\), \(A[n]\)]]\)\), \!\(
\*SubscriptBox[\(\[Limit]\), \(n -> 
\*SuperscriptBox[\(5\), \(+\)]\)]\(ArcTan[
\*FractionBox[\(B[n]\), \(A[n]\)]]\)\), \!\(
\*SubscriptBox[\(\[Limit]\), \(n -> 
\*SuperscriptBox[\(6\), \(+\)]\)]\(ArcTan[
\*FractionBox[\(B[n]\), \(A[n]\)]]\)\), \!\(
\*SubscriptBox[\(\[Limit]\), \(n -> 
\*SuperscriptBox[\(7\), \(+\)]\)]\(ArcTan[
\*FractionBox[\(B[n]\), \(A[n]\)]]\)\), \!\(
\*SubscriptBox[\(\[Limit]\), \(n -> 
\*SuperscriptBox[\(8\), \(+\)]\)]\(ArcTan[
\*FractionBox[\(B[n]\), \(A[n]\)]]\)\)}, 
 PlotRange -> {{0*\[Pi], 2*\[Pi]}, Automatic}, Filling -> Axis, 
 Ticks -> {{#, # Pi} & /@ Range[8], Automatic}]

Mathematica 13.2 Notebook file attached.

Entire Code:

f5[x_] := \!\(\*
TagBox[GridBox[{
{"\[Piecewise]", GridBox[{
{"1", 
RowBox[{"0", "<", "x", "<", "1"}]},
{"0", 
RowBox[{"1", "<", "x", "<", "2"}]}
},
AllowedDimensions->{2, Automatic},
Editable->True,
GridBoxAlignment->{"Columns" -> {{Left}}, "Rows" -> {{Baseline}}},
GridBoxItemSize->{"Columns" -> {{Automatic}}, "Rows" -> {{1.}}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.84]}, 
Offset[0.27999999999999997`]}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}},
Selectable->True]}
},
GridBoxAlignment->{"Columns" -> {{Left}}, "Rows" -> {{Baseline}}},
GridBoxItemSize->{"Columns" -> {{Automatic}}, "Rows" -> {{1.}}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.35]}, 
Offset[0.27999999999999997`]}, "Rows" -> {
Offset[0.2], {
Offset[0.4]}, 
Offset[0.2]}}],
"Piecewise",
DeleteWithContents->True,
Editable->False,
SelectWithContents->True,
Selectable->False,
StripWrapperBoxes->True]\)
Plot[f5[x], {x, 0, 2.5}, Exclusions -> None];
T = 2 - 0;
A0 = 2/T*\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(-
\*FractionBox[\(T\), \(2\)]\), 
FractionBox[\(T\), \(2\)]]\(f5[x] \[DifferentialD]x\)\) // Simplify;
A[n_] = 2/T*\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(-
\*FractionBox[\(T\), \(2\)]\), 
FractionBox[\(T\), \(2\)]]\(f5[x]*Cos[
\*FractionBox[\(2*\[Pi]*n*x\), \(T\)]] \[DifferentialD]x\)\) // 
   Simplify;
B[n_] = 2/T*\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(-
\*FractionBox[\(T\), \(2\)]\), 
FractionBox[\(T\), \(2\)]]\(f5[x]*Sin[
\*FractionBox[\(2*\[Pi]*n*x\), \(T\)]] \[DifferentialD]x\)\) // 
   Simplify;
s5[k_, x_] := A0/2 + \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(n = 1\), \(k\)]\((A[n]*Cos[
\*FractionBox[\(2*\[Pi]*n*x\), \(T\)]] + B[n]*Sin[
\*FractionBox[\(2*\[Pi]*n*x\), \(T\)]])\)\) // Simplify;

Plot[{f5[x], s5[11, x]}, {x, 0, 2}, Exclusions -> None, 
 PlotLegends -> "Expressions", 
 PlotStyle -> {Thickness[0.008], Thickness[0.005]}]

Show[ListPlot[Sqrt[A[n]^2 + B[n]^2] /. n -> {1, 2, 3, 4, 5, 6, 7, 8}, 
  PlotRange -> {{0*\[Pi], 2*\[Pi]}, Automatic}, Filling -> Axis, 
  Ticks -> {{#, # Pi} & /@ Range[8], Automatic}], 
 Plot[{Sqrt[A[1]^2 + B[1]^2], Sqrt[A[3]^2 + B[3]^2]}, {\[Omega], 0, 
   6*\[Pi]}]]

ListPlot[{\!\(
\*SubscriptBox[\(\[Limit]\), \(n -> 
\*SuperscriptBox[\(1\), \(+\)]\)]\(ArcTan[
\*FractionBox[\(B[n]\), \(A[n]\)]]\)\), \!\(
\*SubscriptBox[\(\[Limit]\), \(n -> 
\*SuperscriptBox[\(2\), \(+\)]\)]\(ArcTan[
\*FractionBox[\(B[n]\), \(A[n]\)]]\)\), \!\(
\*SubscriptBox[\(\[Limit]\), \(n -> 
\*SuperscriptBox[\(3\), \(+\)]\)]\(ArcTan[
\*FractionBox[\(B[n]\), \(A[n]\)]]\)\), \!\(
\*SubscriptBox[\(\[Limit]\), \(n -> 
\*SuperscriptBox[\(4\), \(+\)]\)]\(ArcTan[
\*FractionBox[\(B[n]\), \(A[n]\)]]\)\), \!\(
\*SubscriptBox[\(\[Limit]\), \(n -> 
\*SuperscriptBox[\(5\), \(+\)]\)]\(ArcTan[
\*FractionBox[\(B[n]\), \(A[n]\)]]\)\), \!\(
\*SubscriptBox[\(\[Limit]\), \(n -> 
\*SuperscriptBox[\(6\), \(+\)]\)]\(ArcTan[
\*FractionBox[\(B[n]\), \(A[n]\)]]\)\), \!\(
\*SubscriptBox[\(\[Limit]\), \(n -> 
\*SuperscriptBox[\(7\), \(+\)]\)]\(ArcTan[
\*FractionBox[\(B[n]\), \(A[n]\)]]\)\), \!\(
\*SubscriptBox[\(\[Limit]\), \(n -> 
\*SuperscriptBox[\(8\), \(+\)]\)]\(ArcTan[
\*FractionBox[\(B[n]\), \(A[n]\)]]\)\)}, 
 PlotRange -> {{0*\[Pi], 2*\[Pi]}, Automatic}, Filling -> Axis, 
 Ticks -> {{#, # Pi} & /@ Range[8], Automatic}]

Untitled-4.nb (78.4 KB)

Something like this:

ListPlot[Table[{n*Pi, Sqrt[A[n]^2 + B[n]^2]/Degree}, {n, 1, 8}], 
 Filling -> Axis, FillingStyle -> Red, 
 Ticks -> {Table[{k Pi, k Pi}, {k, 8}], 
   Table[{k, Quantity[k, "AngularDegrees"]}, {k, 0, 90, 10}]}]

There are two different graphs involved:

You combined both:

By now, Amplitude vs Radian is ok (both for the x-axis and the y-axis):

But Phase vs Radian is not ok (only for the y-axis):

You want degrees instead of radians on the y axis? Then you have to convert the values:

ListPlot[Table[{n*Pi, Limit[ArcTan[B[k]/A[k]],
     k -> n, Direction -> -1]/Degree}, {n, 1, 8}],
 Filling -> Axis, FillingStyle -> Red,
 Ticks -> {Table[{k Pi, k Pi}, {k, 8}],
   Table[{k, Quantity[k, "AngularDegrees"]},
    {k, -90, 0, 30}]}]

Thanks Gianluca Gorni.

I am not sure here for Ticks why we need to put in Table {kPi, kPi} instead of k*Pi, because the results are the same:

Is it necessary to put that {kPi, kPi}? Or is it enough only {k*Pi}?

I think that is something based on this:

But I don’t yet know how to understand this thing…how does this influence things.

The tick specification {a, b} means that in position a we get the tick label b. In the case {Pi,Pi} the effect of is the same as simply Pi, you are right.

If you write simply k instead of {k, Quantity[k, "AngularDegrees"]} you get the numbers without the degree marker.

And regarding the AngularDegree and Degree, what is the difference between these 2? (because the results between them seems to be equal…from what I can see):

Degree is of course Degree, and I think AngularDegree means radian (rad).
And if we want Quantity to remain in Degree then we leave {k, -90, 0}, and if we want to put in Qunatity AngularDegree (which is Radian(Rad)) then we should put {k, -90Pi/180, 0Pi/180}, am I interpreting correctly? Do you know?

When I type Quantity[3, "Degree in the FrontEnd, it does not give me the option "Degrees". I suppose it is safer to write “AngularDegrees”, as it is less ambiguous, as degrees are used also for temperatures.

Try this input:

Quantity[3, "Degrees"] // FullForm

The symbol Degree is much older than the Quantity framework. Degree is a numerical constant, equivalent to Pi/180, the value of a degree in radians. It is not a Quantity.

Degree // FunctionExpand

It is somewhat confusing.

So I should rely on AngularDegree when I want to use Degree, right? (Degree = AngularDegree)
Although it is strange that we have to write AngularDegree instead of Degree when we refer to Degree, although there are both forms of AngularDegree and Degree available. What will be the difference between them then…? When should we use AngularDegree, and when should we use Degree?

I don’t know what to say, Degree has an expression (Pi/180, which is ok), and AngularDegree has no expression, although it tells you in the result that Degree would be AngularDegree…

"AngularDegree" is the official name, and it is a string, not a symbol. Its use is confined to Quantity, UnitConvert and similar functions. If you type Quantity[3,"Degree"], the system automatically replaces "Degree" with "AngularDegree", but you may never realize it, because by default it is displayed as the little o.

Degree is a symbol, not a string. It is replaced by the number Pi/180 when making calculations, like for example GoldenRatio, which is replaced by 1/2 (1 + Sqrt[5]). It is also rendered by the little o.

The output form of 3 Degree looks almost the same as Quantity[3,"Degree"]. I leave it to you to discover the differences.

There is indeed some margin for confusion.