Skip to content
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

Added the recipe 'vectorfieldplot' for plotting 2d vector field functions #4979

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from

Conversation

m0rninglightmountain
Copy link

@m0rninglightmountain m0rninglightmountain commented Sep 4, 2024

Fixes #4890

Description

This Pull request adds a new recipe, Vectorfieldplot(), based on the Recipebase package. The recipe enhances the plotting capabilities by providing a straightforward method for visualizing 2D vector fields.

  • Function Input: The plot accepts a single function as an argument, which defines the vector field to be visualized. This function should take two arguments (x, y coordinates) and return a 2-tuple representing the vector components (u, v).

  • Plot Customization: The plot includes customizable attributes such as axis limits, grid lines, ticks, and labels. The vectors are plotted using a quiver plot style, with arrows representing the direction and magnitude of the field at each grid point. Here's the list of customizable attributes :

    Plot attributes

      xlabel 
      ylabel 
      title 
      xlims 
      ylims 
      xticks 
      yticks 
      grid 
      minorgrid 
      gridlinewidth 
      gridstyle 
      gridalpha 
      legend
    
    

Usage

This is the step-wise instruction to use vectorfieldplot :

  1. Import the Plots package:
using Plots
  1. Define the vector field function. For example, a simple rotational field can be defined as:
function rotational_field(x, y)
return (-y, x) 
end
  1. Create a VectorFieldPlot with the defined function:
vectorfieldplot(rotational_field)
  1. Customize the plot if needed by adjusting the steps, axis limits, and other attributes:
VectorFieldPlot(rotational_field, steps=25, xlims=(-5, 5), ylims=(-5, 5))

Here's the graph of the vector field function generated using the above code:

Screenshot 2024-09-04 at 8 20 01 PM

Things to consider

  • Does it work on log scales?
  • Does it work in layouts?
  • Does it work in recipes?
  • Does it work with multiple series in one call?
  • PR includes or updates tests?
  • PR includes or updates documentation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FR] Allow plotting function data in quiver()
1 participant