Fplot Color

Posted on by admin

A thin wrapper for matplotlib

Fplot's goal is to provide simple syntax for plotting functions, with sensibledefaults. Matplotlib is powerful, but has awkward syntax, odd default display settings,and requires setting up data arrays manually. Making pretty function plots requiresmultiple lines of code. Fplot aims to fix this; it's especially suited for visualizingfunctions when learning math.

Fplot Color

Python 3 only.

Included functions

Summary fplot is a general purpose plotting package, with functionality roughly similar to gnuplot. It is a command-line driven tool; you can also supply instructions in a script file. Fplot has its particular strengths and weaknesses, but for the Questaal suite it is particularly useful because it synchronises smoothly with other Questaal executables such as plbnds and pldos, and shares a. Marker fill color, specified as 'auto', an RGB triplet, a hexadecimal color code, a color name, or a short name. The 'auto' value uses the same color as the MarkerEdgeColor property. For a custom color, specify an RGB triplet or a hexadecimal color.

Color
  • plot: One input, one output.
  • parametric: One input, two or three outputs. If three, use a 3d graph.
  • contour: Two inputs, one output.
  • surface: Two inputs, one output.
  • vector: Two inputs, two outputs.
  • vector3d: Three inputs, three outputs.
  • polar: One input (angle), one output (radius)

Bonus functions

  • plot2: Smoothed API for matplotlib 2d plotting that works properly in Jupyter notebooks. ie syntax like plt.plot, which doesn't work properly in Jupyter. Arguments: (args, marker='b-', linewidth: float=2.0, grid: bool=False, color: str=None, title: str=None, equal_aspect: bool=False, style: str=None, show: bool=True)
  • imshow: Like plot2, but as a replacement for plt.imshow.
  1. Uses adaptive step control to produce a representative graph, concentrating its evaluation in regions where the function's rate of change is the greatest. Examples Plot the hyperbolic tangent function from -2 to 2.
  2. Plot a function between specified limits. See LineSpec for more information. Fplot(fun,limits,n) with n = 1 plots the function with a minimum of n+1 points.

Installation

Basic documentation

The only required arguments for fplot funcs are the function to plot, and themin and max ranges. Example optional keyword arguments are shown. Example outputis shown in the link above.

For most plotting functions, you can plot multiple functions at once by passinga list or tuple as the first argument.

Show a graph (1 input, 1 output)

Show a contour plot (2 inputs, 1 output)

Show a surface plot (2 inputs, 1 output)

Show a 2d parametric plot (1 input, 2 outputs)

Show a 3d parametric plot (1 input, 3 outputs)

Show a 2d vector plot (2 inputs, 2 outputs)

Show a 3d vector plot (3 inputs, 3 outputs)

Show a 2d polar plot (1 input, 1 output)

Example of an interactive plot with Ipython widgets in Jupyter notebook

Optional arguments:
  • show: Defaults to True. Instantly display the plot. If False, return the axis object.
  • resolution: Controls how many points to draw, based on function input. Higher resolutionallows more zooming, but may lower performance.
  • color: (ie line color)
  • linewidth: line width.
  • y_min and y_max: (only for 2d input)
  • theta_min and theta_max (only for polar plots)
  • style: (ie from plt.use.style())
  • grid: defaults to True
  • equal_aspect: defaults to False
  • title: Shown at the top of the plot
  • stream: vector plot only; show a stream plot if True
  • contours: surface plot only; show contour plots along each axis if True
  • num_contours: contour plot only; set number of contour lines to draw. Defaults to 10.

L. Oberbroeckling, Spring 2018.

Contents

This document gives BASIC ways to color graphs in MATLAB. See

and

for more in-depth explanations and fancier coloring, to name just two sources.

Default Colors in 2D Graphs

The default colors used in MATLAB changed in R2014b version. Here are the colors, in order, and their MATLAB RGB triplet.

Current colorOld color
[0, 0.4470, 0.7410][0, 0, 1]
[0.8500, 0.3250, 0.0980][0, 0.5, 0]
[0.9290, 0.6940, 0.1250][1, 0, 0]
[0.4940, 0.1840, 0.5560][0, 0.75, 0.75]
[0.4660, 0.6740, 0.1880][0.75, 0, 0.75]
[0.3010, 0.7450, 0.9330][0.75, 0.75, 0]
[0.6350, 0.0780, 0.1840][0.25, 0.25, 0.25]

Another thing that changed starting in the R2014b version is that the hold on and hold off automatically cycles through the colors. In the past, each new plot command would start with the first color (blue) and you would have to manually change the color. Now it will automatically move to the next color(s). See below for how to manually adjust the colors.

Fplot Color

Default Colors in 3D Graphs

If using mesh(x,y,z), to change the look of it you would want to change 'EdgeColor'. Note that the name of this colormap is 'parula' while previous to R2014b, it was 'jet'

Using Basic Colors in Graphs

The eight basic colors are known by either their short name or long name (RGB triplets are also included).

Long NameShort NameRGB Triplet
blueb[0,0,1]
blackk[0,0,0]
redr[1,0,0]
greeng[0,1,0]
yellowy[1,1,0]
cyanc[0,1,1]
magentam[1,0,1]
whitew[1,1,1]

Example of how to change the color using short names is below. You can easily do the same thing using the long names.

Changing Colors

Many times you want to have more control of what colors are used. For example, I may want some data points drawn in the same color as the curve. Or I have a piece-wise graph that I want to have all the same color. There are several ways to do this. One is to use the default colors and 'resetting' the order, which is shown here. Others involve using the RGB triplet (see next section).

As you may see, this could get confusing to keep track of. Thus it may be easier to use the RGB triplets, and even name them ahead of time. This is discussed in the section below.

Using RGB triplets to change colors

One can specify colors using a vector that gives the RGB triple where in MATLAB, each of the three values are numbers from 0 to 1. Usually RGB colors have values from 0 to 255. You can use those numbers and divide the vector by 255 to use within MATLAB. Thus knowing the MATLAB RGB triples for the colors can be useful. From the table above, we can define the default colors to work with them or can put in the RGB triplet (as a vector) directly into the plot command. Both are shown in this example.

For other colors, you can look up their RGB code on many websites such as RGB Color Codes Chart or HTML Color Picker to see the RGB codes (or hex codes, etc.) For example, at these RGB Color websites, you will be given R=255, G=0, B=0 for red. So you can use 1/255[255,0,0] to get the color of red to use as a color in MATLAB.

The official color for Loyola Green is given as RGB:0-104-87, and Loyola Gray is given as RGB:200-200-200 (found on Loyola's Logos/University Signature page. Here's how one can use those colors in MATLAB.

Now one can use these colors to specify the color of markers, lines, edges, faces, etc.

Changing colors in 3D Graphs

If using mesh(x,y,z), to change the look of it you can change to a different colormap as discussed in https://www.mathworks.com/help/matlab/ref/colormap.html. This was done above when showing the previous default colormap. Here are some more.

Warning! Once you change the colormap, it will keep that colormap for all subsequent 3D plots within the same figure or MATLAB session until you use close, or open a new figure window.

Plot Color

For mesh and surf, you can change 'EdgeColor' and/or 'FaceColor' to be uniform, rather than using colormaps.

Plot Colors Python


Published with MATLABĀ® R2016a