How to use the command fdp (with examples)
The fdp
command is a part of the graphviz
package, and it is used to render an image of a force-directed
network graph from a graphviz
file. It supports various layouts such as dot
, neato
, twopi
, circo
, fdp
, sfdp
, osage
, and patchwork
. The fdp
command provides several options to generate network graphs in different output formats like png
, svg
, ps
, pdf
, fig
, gif
, jpg
, json
, and dot
.
Use case 1: Render a png
image with a filename based on the input filename and output format (uppercase -O):
Code:
fdp -T png -O path/to/input.gv
Motivation: This use case is useful when you want to generate a png
image of a network graph from a graphviz
file, and the output filename is based on the input filename.
Explanation:
fdp
: The command to render the image.-T png
: Specifies the output format aspng
.-O path/to/input.gv
: Sets the output file name based on the input file name.
Example output: The fdp
command will generate a png
image of the network graph based on the input.gv
file and save it as path/to/input.png
.
Use case 2: Render a svg
image with the specified output filename (lowercase -o):
Code:
fdp -T svg -o path/to/image.svg path/to/input.gv
Motivation: This use case is useful when you want to generate an svg
image of a network graph from a graphviz
file and specify a custom output filename.
Explanation:
fdp
: The command to render the image.-T svg
: Specifies the output format assvg
.-o path/to/image.svg
: Sets the output file name aspath/to/image.svg
.path/to/input.gv
: The input file name.
Example output: The fdp
command will generate an svg
image of the network graph based on the input.gv
file and save it as path/to/image.svg
.
Use case 3: Render the output in a specific format:
Code:
fdp -T ps|pdf|svg|fig|png|gif|jpg|json|dot -O path/to/input.gv
Motivation: This use case is useful when you want to render the output network graph in a specific format other than the default png
or svg
formats.
Explanation:
fdp
: The command to render the image.-T
: Specifies the output format. It can be one of the following:ps
,pdf
,svg
,fig
,png
,gif
,jpg
,json
, ordot
.-O path/to/input.gv
: Sets the output file name based on the input file name.
Example output: The fdp
command will generate an image of the network graph based on the input.gv
file and save it in the specified format (e.g., ps
, pdf
, svg
, etc.).
Use case 4: Render a gif
image using stdin
and stdout
:
Code:
echo "digraph {this -> that} " | fdp -T gif > path/to/image.gif
Motivation: This use case is useful when you want to generate a gif
image of a network graph from the stdin
input and save it with a custom filename.
Explanation:
echo "digraph {this -> that} "
: Provides thedot
representation of the network graph as input usingstdin
.|
: The pipe symbol is used to redirect the output of theecho
command to thefdp
command.fdp -T gif
: Specifies that the output format should begif
.> path/to/image.gif
: Redirects the output of thefdp
command to the filepath/to/image.gif
Example output: The fdp
command will generate a gif
image of the network graph provided in the stdin
(in this case, a simple graph with a single edge) and save it as path/to/image.gif
.
Use case 5: Display help:
Code:
fdp -?
Motivation: This use case is useful when you want to view the help information and usage examples of the fdp
command.
Explanation:
fdp
: The command to render the image.-?
: Displays the help information for thefdp
command.
Example output: The fdp
command will display the help text, which includes usage examples and additional information about the fdp
command.