# Does not plot if change array

This program is very simple, but I do not understand why it works when I use ξ_ar = 0.00001:0.01:10 but it does not when ξ_ar = 0.00001:0.000001:10 .

using ModelingToolkit;
using LaTeXStrings;
using Plots;

@variables(begin
ξ
end);

αₙ = 1/(3 + 12ξ - 2sqrt(6ξ*(6ξ+1)))
wₑ = 2/3αₙ - 1
wₑ_bf = ModelingToolkit.build_function(wₑ, ξ, expression=false)

ξ_ar = 0.00001:0.01:10 #This can be plotted, but if I use ξ_ar = 0.00001:0.000001:10 it will not be plotted
wₑ_ar = wₑ_bf.(ξ_ar)
plot(ξ_ar,wₑ_ar,
title = L"w_{eff} = \frac{2}{3\alpha} - 1",
color = "blue",
label = L"\alpha = \frac{1}{3  + 12\xi - 2\sqrt{6\xi\left(6\xi + 1\right)}}",
linewidth = 2,
legend = :topright,
widen = :false,
xscale = :log10,
ylim = [0.2,1.1],
framestyle = :box,
xaxis = L"\xi",
yaxis = L"w_{eff}"
)

I have updated Plots.jl and I also ran ] test Plots and everything seems fine.

This is the julia version I am using:

PS C:\Users\luisl> julia --version
julia version 1.7.3

These are my packages and its versions:

(@v1.7) pkg> st
Status C:\Users\luisl\.julia\environments\v1.7\Project.toml
[0c46a032] DifferentialEquations v7.1.0
[7073ff75] IJulia v1.23.3
[b964fa9f] LaTeXStrings v1.3.0
[961ee093] ModelingToolkit v8.14.0
[91a5bcdd] Plots v1.29.1
[d1185830] SymbolicUtils v0.19.9
[0c5d862f] Symbolics v4.6.1
[1986cc42] Unitful v1.11.0

I hope you can help

julia> a = 0.00001:0.000001:10
1.0e-5:1.0e-6:10.0

julia> length(a)
9999991

This range has nearly 10 million points in it! Do you really need such a precise plot?

Based on the code I showed that is a good point. Maybe I needed to be more explicit.
I have been working with ModelingToolkit.jl and DifferentialEquations.jl and I had the same issue. Now, for a case much more simple I get the same problem.
I wonder if there is something I am missing in order to plot arrays with such a number of points.

Your problem is probably you’re trying to plot too many points. There is no real solving that without reducing the number, there will always be some limit to how much stuff you can fit in a plot.

You could try to use InspectDR.jl which is pretty good at handling a large number of points as long as you use simple diagram types…

1 Like

If your ultimate goal is just to get a plot of this function, there is no need for ModelingToolkit.

And whether or not you use ModelingToolkit, rather than manually specifying the range of \xi, you might be interested in knowing that you can pass a function directly as the argument to plot with the desired x-range and it will figure out a good number of points for you:

using Plots
α(ξ) = 1/(3 + 12ξ - 2sqrt(6ξ*(6ξ+1)))
w(ξ) = 2/3α(ξ) - 1
plot(w, 0, 10)

By inspecting your function, it is clear that increasing the number of points will do little to change the look of this plot: At any normal resolution, 0.000001 on this scale is muuuuch smaller than a pixel.

1 Like