How to plot two functions in one plot with different y-axis in Mathematica? - plot

I would like to plot two functions in one plot with one x-axis and two different y-axis. I tried to used the overlay function but the result cannot be satisfied.
ZS1 = {{820, 30}, {860, 40}, {880, 50}, {900, 60}, {920, 70}, {930,
80}, {940, 90}};
plot1 = ListLinePlot[ZS1, PlotStyle -> Blue,
Frame -> {True, True, True, False},
ImagePadding -> 25,
FrameStyle -> {Automatic, Blue, Automatic, Automatic}]
theta1 = {{980, 0.3}, {960, 0.4}, {920, 0.5}, {880, 0.8}, {800,
1.1}};
plot2 = ListLinePlot[theta1, PlotStyle -> Red,
ImagePadding -> 25, Axes -> False,
Frame -> {True, False, False, True},
FrameTicks -> {{None, All}, {All, None}},
FrameStyle -> {Automatic, Automatic, Automatic, Red}]
Overlay[{plot1, plot2}]

I accomplished by using the "CombinePlots" function.
ResourceFunction["CombinePlots"][ListLinePlot[ZS1, PlotStyle -> Blue, Frame -> True, FrameStyle -> Blue], ListLinePlot[theta1, PlotStyle -> Red, Frame -> True, FrameStyle -> Red], "AxesSides" -> "TwoY", FrameLabel -> {Style["Frequency (MHz)", 14], Style["ZS1", 14], None, Style["\[Theta]1", 14]}, GridLines -> Automatic]

Related

DiagrammeR - how to move labels outside of nodes

How can I move labels outside of the circles utilizing R's DiagrammeR package? I don't see anything in the instruction manual. Here's my code. In my opinion it's not visually appealing to have the labels inside the circles. If I could apply ggrepel to DiagrammeR that would be ideal, although I doubt this is possible.
library(DiagrammeR)
grViz("
digraph neato {
graph [layout = neato]
node [shape = circle,
style = filled,
color = grey,
label = '']
node [fillcolor = red]
a [label='Amelia Arduino', fixedsize = true]
node [fillcolor = green]
b c d
node [fillcolor = orange]
l [label = 'Larry Lamp', fixedsize = true]
edge [color = grey]
a -> {b c d}
b -> {e f g h i j}
c -> {k l m n o [label = 'Ophelia Oz', fixedsize = true]
p [label = 'Peter Pete', fixedsize = true]}
d -> {q r s t u v}
}")

Plots with in-texts (with specificed positions) in Mathematica

I have a plot where I plot different equations in each chunk of the graph. Using text, I want to write a small notation for each piece of the equation. The Text function does not yield the result. Also is there a way to specify the coordinates of the text? For example, I want the text reading Eqn 1 (see below) to be placed at (0, 0.5)
Here is my code:
Pars = {ep -> 0.5, f1p -> 0.3, f2p -> 0.1, dp -> 0.05, q -> 0.1,
en -> 0.4, d -> 0.1, Q -> 0.1, f2n -> 0.3, f1n -> 0.4, a -> 0.05,
N1 -> 0.5, N2 -> 0.5}; #Parameters
PlotREq1 =
Plot[R = S /. Pars, {S, 0, 0.9375},
PlotRange -> {{0, 3.5}, {0, 2}}, PlotStyle -> {Red, Thick, Dashed},Text[Eqn1]];
PlotREq2 =
Plot[R = (a + d)/(en f1n) /. Pars, {S, 0.9375, 1.4375},
PlotRange -> {{0, 3.5}, {0, 2}}, PlotStyle -> {Green, Thick, Dashed}, Text[Eqn2]];
PlotREq3 =
Plot[R = ((a + d) (f1p - f2p))/(en (f1p f2n - f1n f2p)) /. Pars, {S,
1.4375, 2.3}, PlotRange -> {{0, 3.5}, {0, 2}},
PlotStyle -> {Blue, Thick, Dashed}, Text[Eqn3]];
Show[PlotREq1, PlotREq2, PlotREq3]
Show[PlotREq1, PlotREq2, PlotREq3,
Epilog -> {
Inset[Framed[Style["Eqn 1", 14], Background -> White, FrameStyle -> None], {0.5, 0.5}],
Inset[Style["Eqn 2", 14], {1.18, 1.05}],
Inset[Style["Eqn 3", 14], {1.9, 1.6}]}]

Plotting multiple gridlines and give seperate labels in Mathematica

I am trying to make the following plot:
Pars = {ep -> 0.5, f1p -> 0.3, f2p -> 0.1, dp -> 0.05, q -> 0.1,
en -> 0.4, d -> 0.1, Q -> 0.1, f2n -> 0.3, f1n -> 0.4, a -> 0.05,
N1 -> 0.5, N2 -> 0.5}; #Parameters
PlotREq1 =
Plot[R = S /. Pars, {S, 0, 0.9375},
PlotRange -> {{0, 3.5}, {0, 2}}, PlotStyle -> {Red, Thick, Dashed},
GridLines -> {{0.9375}, {}}];
PlotREq2 =
Plot[R = (a + d)/(en f1n) /. Pars, {S, 0.9375, 1.4375},
PlotRange -> {{0, 3.5}, {0, 2}}, PlotStyle -> {Red, Thick, Dashed},
GridLines -> {{1.4375}, {}}];
PlotREq3 =
Plot[R = ((a + d) (f1p - f2p))/(en (f1p f2n - f1n f2p)) /. Pars, {S,
1.4375, 2.3}, PlotRange -> {{0, 3.5}, {0, 2}},
PlotStyle -> {Red, Thick, Dashed}, GridLines -> {{2.3}, {}}];
Show[PlotREq1, PlotREq2, PlotREq3]
However, only the first gridline shows up and the other two vertical lines at 1.4375 and 2.3 do not appear. Also, can anyone suggest a way to label the gridlines? I tried to insert a axeslabel within the Gridline function as: Gridlines -> {{{0.9375},{}}, AxesLabel -> {"R",""}} but it does not seem to work.
Using Show, only the first version of an option is followed. Place all the gridlines in the first plot, or add them as options to Show, which will override any others.
Show[PlotREq1, PlotREq2, PlotREq3, GridLines -> {{0.9375, 1.4375, 2.3}, {}}]

How to animate a 3d plot using python?

I have this python code:
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as axes3d
from matplotlib import cm
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Plot solid of revolution along x-axis
def sor_x(ll, ul):
u = np.linspace(ll, ul, 60)
v = np.linspace(0, 2 * np.pi, 60)
U, V = np.meshgrid(u, v)
X = U
Y = (U**2)*np.cos(V)
Z = (U**2)*np.sin(V)
ax.set_xlabel('X axis')
ax.set_ylabel('Y axis')
ax.set_zlabel('Z axis')
ax.plot_surface(X, Y, Z, cmap=plt.cm.YlGnBu_r)
if __name__ == '__main__':
ll, ul = 0, 1
sor_x(ll, ul)
plt.show()
This plots the solid of revolution of function y = x**2 along x-axis. Now I have to change this to a 3D animation like this:
The code for this animation in mathematica is:
f[r_, ϕ_, z_] := {(2 + Tan[z])Cos[ϕ], (2 + Cos[z]) Sin[ϕ], z}
vase[α_] :=
ParametricPlot3D[f[r, ϕ, z], {z, 0, 2 Pi}, {ϕ, 0, α},
AspectRatio -> Automatic, PlotRange -> {{-3, 3}, {-3, 3}, {0, 6}}];
animation = Table[
vase[ϕ],
{ϕ, 0.1, 2π, π/12}];
Export["rotationskoerper_animation.gif", animation,
ConversionOptions -> {"AnimationDisplayTime" -> 0.1, "Loop" -> True},
ImageSize -> {1000, 1000}]

White area in Mathematica ListPlot

When I create and plot this list:
var = 2;
okList = {{0.8, var, 0.8, 0.8}, {0, 0.3, 0.6, 0.9}, {0, 1, 2, 3}};
lp = ListDensityPlot[okList, ColorFunction -> "SandyTerrain"]
or, unscaled, like this:
lp = ListDensityPlot[okList, ColorFunction -> "SandyTerrain",
ColorFunctionScaling -> False]
I get a fully coloured square, as I'd expect.
But when I try this:
var = 0.8;
list = {{0.8, var, 0.8, 0.8}, {0, 0.3, 0.6, 0.9}, {0, 1, 2, 3}};
problem = ListDensityPlot[list, ColorFunction -> "SandyTerrain"]
I get a white patch in the corner.
which plotting with ColorFunctionScaling->False doesn't get rid of
The ColorFunction SandyTerrain doesn't have any white in it, so this must be ListDensityPlot not plotting anything in that area.
What could cause this to happen, and how do I stop it?
It's getting clipped by the automatic plot range calculation. Try with PlotRange -> All or ClippingStyle -> Automatic.

Resources