Plotting
The plotting functions within magnetopy
handle many basic use cases but are unlikely to provide exactly what's needed for specific project needs, and the user may still need to be able to make their own plots. Some of the utility functions herein may be helpful in that regard.
linear_color_gradient(start_color, finish_color='white', n=10)
Return a list of colors forming linear gradients between two colors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_color |
HexColorCode | basic_colors
|
The starting color as either a hex code (e.g. "#FFFFFF") or a basic color name. |
required |
finish_color |
HexColorCode | basic_colors
|
The ending color as either a hex code (e.g. "#FFFFFF") or a basic color name, by default "white" |
'white'
|
n |
int | Sized
|
The number of colors to return, by default 10. |
10
|
Returns:
Type | Description |
---|---|
list[HexColorCode]
|
A list of hex color codes forming a linear gradient between the start and finish colors. |
Notes
Supported basic colors includes: "red", "orange", "yellow", "green", "blue", "purple", "black", and "white".
References
Source code in magnetopy\plot_utils.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
default_colors(n)
Return a list of colors for plotting. The default colors are the first 10 colors from the Matplotlib default color cycle. If more than 10 colors are requested, the default colors are cycled.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int | Sized
|
The number of colors to return or a list-like object of the same length as the number of colors to return. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
A list of colors for plotting. |
Source code in magnetopy\plot_utils.py
force_aspect(ax, aspect=1)
Force the aspect ratio of a plot to be a certain value. Uses the axes's current x and y limits to calculate the aspect ratio. Works for both linear and log scales.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ax |
plt.Axes
|
The axes to force the aspect ratio of. |
required |
aspect |
int
|
The desired aspect ratio, by default 1. |
1
|
Source code in magnetopy\plot_utils.py
handle_kwargs(**kwargs)
Returns a dictionary with either user-entered or default values for the
arguments supported by handle_options()
.
Also supports a "save" arguments which will save the figure to the specified filename if it is not None.
Source code in magnetopy\plot_utils.py
handle_options(ax, options, label=None, title=None)
Handles some of the typical options for plotting functions in matplotlib. The currently supported options are in the parameter list below.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ax |
plt.Axes
|
The axes to handle the options for. |
required |
options |
dict[str, str]
|
A dictionary of options. The currently supported options are: - "xlim": A tuple of the x-axis limits. - "ylim": A tuple of the y-axis limits. - "loc": The location of the legend. - "xlabel": The x-axis label. - "ylabel": The y-axis label. - "title": The title of the plot. |
required |
label |
str
|
The label for the legend, by default None. |
None
|
title |
str
|
The title of the plot, by default None. |
None
|