-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple interface for plot field for both time and frequency #20
Comments
Am struggling to get the right dispatch behaviour...
Have a look at the first function in plots.jl. plot(SimulationResult) works, but plot(SimulationResult, linetype=:contour) and plot(SimulationResult, linetype=:field) do not... |
Plots is quite complicated because linetype can be define in several ways, in commit 7a66332 I use Another thing to think about is, should we allow surface type plots? These can accept vectors of x, y and z with no real structure and infer a triangular interpolation. Using something like this would mean we wouldn't have to assume that the user provided Here's a quick example to show surface plots with unstructured sample points: rx = 2.*(rand(1000).-0.5)
ry = 2.*(rand(1000).-0.5)
surface(rx,ry,rx.^2.+ry.^2) |
A simulation result can have any number of angular frequencies or positions. What if we pretty much ignore linetype and have plot(simresult, :, ω) # Plot all positions for one angular frequency, i.e. contour
plot(simresult, x, :) # Plot one position for all angular frequencies, i.e. line We can then detect PS: are ω and x the wrong way around everywhere? Does it make sense to have angular frequency or position first? |
- Change references to linetype to seriestype to allow user to change the plot type - Change plot(::FrequencySimulationResult) to dispatch based on indexes which are passed in
- plot(simres; kws...) show line plots, where kws can include x_indices = .. - plot(simres, omega; seriestype=:surface, kws..) and plot(simres, omega; seriestype=:contour) show a surface and contour plot.
Here is my suggestion. I know you don't love keywords! But for me this the most useful and intuitive option:
What do you think? |
And sorry it currently does not work and I couldn't find why! I have to run off and enjoy Kyoto now. |
Contour and surface are entirely a matter of taste, and we should really be able to do both whatever the user gives us. I just can't seem to get contour to accept unstructured data or, equally, extract the contour plot embedded in surface. I think without significant effort, for now we are limited by what plots can cope with. Also, surface looks odd from above, it's only really useful from an angle. The reason I specialised the function to frequencies was because Absolutely, indices are not the most natural way of interacting for a user, I intended to implement a wrapper function much like you have. Although I intended to make more use of dispatch rather than keywords, but I quite like how you've done it. I'm not generally a big fan of keywords if the same thing can be achieved without them, but for high level stuff like plotting they can make a lot of sense. |
Yes, just adding some wrappers for your index function would be nice. I just didn't think of it at the time! The cause of the error was the weirdest thing: @recipe function myplot(x::Vector{Int}; t::AbstractFloat = 2.)
(x,t*x)
end but then plot([1:2])
>ERROR: MethodError: Cannot `convert` an object of type Expr to an object of type Symbol
but if you don't type declare the keyword @recipe function myplot(x::Vector{Int}, y::Int; t = 2)
(x,t*x)
end that is, |
I think the following should work:
plot(SimulationResult)
should return several lines plots for each xplot(SimulationResult, linetype=:contour)
should attempt a contour plot. This should work for bothTimeSimulationResult
andFrequencySimulationResult
. Note the functionrun(Simulation,shape)
can return bothTimeSimulationResult
andFrequencySimulationResult
, which can then be plottedplot(FrequencySimulation, ω)
should generate a contour plot.There might be a dispatch issue for the first two, as I'm struggling to get plot recipes to do this...
The text was updated successfully, but these errors were encountered: