pandas_openscm.plotting#
Plotting
Classes:
| Name | Description |
|---|---|
MissingQuantileError |
Raised when a quantile(s) is missing from a pd.DataFrame |
PlumePlotter |
Object which is able to plot plume plots |
SingleLinePlotter |
Object which is able to plot single lines |
SinglePlumePlotter |
Object which is able to plot single plumes |
Functions:
| Name | Description |
|---|---|
create_legend_default |
Create legend, default implementation |
extract_single_unit |
Extract the unit of the data, expecting there to only be one unit |
fill_out_dashes |
Fill out dashes |
fill_out_palette |
Fill out a palette |
get_default_colour_cycler |
Get the default colour cycler |
get_default_dash_cycler |
Get the default dash cycler |
get_pdf_from_pre_calculated |
Get a pd.DataFrame for plotting from pre-calculated quantiles |
get_quantiles |
Get just the quantiles from a QUANTILES_PLUMES_LIKE |
get_values_line |
Get values for plotting a line |
get_values_plume |
Get values for plotting a line |
plot_plume_after_calculating_quantiles_func |
Plot a plume plot, calculating the required quantiles first |
plot_plume_func |
Plot a plume plot |
same_shape_as_x_vals |
Validate that the received values are the same shape as |
Attributes:
| Name | Type | Description |
|---|---|---|
COLOUR_VALUE_LIKE |
TypeAlias
|
Type that allows a colour to be specified in matplotlib |
DASH_VALUE_LIKE |
TypeAlias
|
Types that allow a dash to be specified in matplotlib |
PALETTE_LIKE |
TypeAlias
|
Palette-like type |
QUANTILES_PLUMES_LIKE |
TypeAlias
|
Type that quantiles and the alpha to use for plotting their line/plume |
COLOUR_VALUE_LIKE
module-attribute
#
COLOUR_VALUE_LIKE: TypeAlias = Union[
Union[
str,
tuple[float, float, float],
tuple[float, float, float, float],
tuple[
Union[tuple[float, float, float], str], float
],
tuple[tuple[float, float, float, float], float],
],
]
Type that allows a colour to be specified in matplotlib
DASH_VALUE_LIKE
module-attribute
#
Types that allow a dash to be specified in matplotlib
PALETTE_LIKE
module-attribute
#
PALETTE_LIKE: TypeAlias = Mapping[T, COLOUR_VALUE_LIKE]
Palette-like type
QUANTILES_PLUMES_LIKE
module-attribute
#
QUANTILES_PLUMES_LIKE: TypeAlias = tuple[
Union[
tuple[float, float],
tuple[tuple[float, float], float],
],
...,
]
Type that quantiles and the alpha to use for plotting their line/plume
MissingQuantileError #
Bases: KeyError
Raised when a quantile(s) is missing from a pd.DataFrame
Methods:
| Name | Description |
|---|---|
__init__ |
Initialise the error |
Source code in src/pandas_openscm/plotting.py
__init__ #
__init__(
available_quantiles: Collection[float],
missing_quantiles: Collection[float],
) -> None
Initialise the error
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
available_quantiles
|
Collection[float]
|
Available quantiles |
required |
missing_quantiles
|
Collection[float]
|
Missing quantiles |
required |
Source code in src/pandas_openscm/plotting.py
PlumePlotter #
Object which is able to plot plume plots
Methods:
| Name | Description |
|---|---|
from_df |
Initialise from a pd.DataFrame |
generate_legend_handles |
Generate handles for the legend |
plot |
Plot |
Attributes:
| Name | Type | Description |
|---|---|---|
dashes |
dict[Any, str | tuple[float, tuple[float, ...]]] | None
|
Dashes used for plotting different values of the style variable |
hue_var_label |
str
|
Label for the hue variable in the legend |
lines |
Iterable[SingleLinePlotter]
|
Lines to plot |
palette |
PALETTE_LIKE[Any]
|
Palette used for plotting different values of the hue variable |
plumes |
Iterable[SinglePlumePlotter]
|
Lines to plot |
quantile_var_label |
str
|
Label for the quantile variable in the legend |
style_var_label |
str | None
|
Label for the style variable in the legend (if not |
x_label |
str | None
|
Label to apply to the x-axis (if |
y_label |
str | None
|
Label to apply to the y-axis (if |
Source code in src/pandas_openscm/plotting.py
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 | |
dashes
instance-attribute
#
Dashes used for plotting different values of the style variable
palette
instance-attribute
#
palette: PALETTE_LIKE[Any]
Palette used for plotting different values of the hue variable
quantile_var_label
instance-attribute
#
quantile_var_label: str
Label for the quantile variable in the legend
style_var_label
instance-attribute
#
style_var_label: str | None
Label for the style variable in the legend (if not None)
x_label
instance-attribute
#
x_label: str | None
Label to apply to the x-axis (if None, no label is applied)
y_label
instance-attribute
#
y_label: str | None
Label to apply to the y-axis (if None, no label is applied)
from_df
classmethod
#
from_df(
df: DataFrame,
*,
quantiles_plumes: QUANTILES_PLUMES_LIKE = (
(0.5, 0.7),
((0.05, 0.95), 0.2),
),
quantile_var: str = "quantile",
quantile_var_label: str | None = None,
quantile_legend_round: int = 2,
hue_var: str = "scenario",
hue_var_label: str | None = None,
palette: PALETTE_LIKE[Any] | None = None,
warn_on_palette_value_missing: bool = True,
style_var: str | None = "variable",
style_var_label: str | None = None,
dashes: dict[Any, str | tuple[float, tuple[float, ...]]]
| None = None,
warn_on_dashes_value_missing: bool = True,
linewidth: float = 3.0,
unit_var: str | None = "unit",
unit_aware: bool | UnitRegistry = False,
time_units: str | None = None,
x_label: str | None = "time",
y_label: str | bool | None = True,
warn_infer_y_label_with_multi_unit: bool = True,
observed: bool = True,
) -> PlumePlotter
Initialise from a pd.DataFrame
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
pd.DataFrame from which to initialise |
required |
quantiles_plumes
|
QUANTILES_PLUMES_LIKE
|
Quantiles to plot in each plume. If the first element of each tuple is a tuple, a SinglePlumePlotter object will be created. Otherwise, if the first element is a plain float, a SingleLinePlotter object will be created. |
((0.5, 0.7), ((0.05, 0.95), 0.2))
|
quantile_var
|
str
|
Variable/column in the multi-index which stores information about the quantile that each timeseries represents. |
'quantile'
|
quantile_var_label
|
str | None
|
Label to use as the header for the quantile section in the legend |
None
|
quantile_legend_round
|
int
|
Rounding to apply to quantile values when creating the legend |
2
|
hue_var
|
str
|
Variable to use for grouping data into different colour groups |
'scenario'
|
hue_var_label
|
str | None
|
Label to use as the header for the hue/colour section in the legend |
None
|
palette
|
PALETTE_LIKE[Any] | None
|
Colour to use for the different groups in the data. If any groups are not included in |
None
|
warn_on_palette_value_missing
|
bool
|
Should a warning be emitted if there are values missing from |
True
|
style_var
|
str | None
|
Variable to use for grouping data into different (line)style groups |
'variable'
|
style_var_label
|
str | None
|
Label to use as the header for the style section in the legend |
None
|
dashes
|
dict[Any, str | tuple[float, tuple[float, ...]]] | None
|
Dash/linestyle to use for the different groups in the data. If any groups are not included in |
None
|
warn_on_dashes_value_missing
|
bool
|
Should a warning be emitted if there are values missing from |
True
|
linewidth
|
float
|
Width to use for plotting lines. |
3.0
|
unit_var
|
str | None
|
Variable/column in the multi-index which stores information about the unit of each timeseries. |
'unit'
|
unit_aware
|
bool | UnitRegistry
|
Should the values be extracted in a unit-aware way? If |
False
|
time_units
|
str | None
|
Units of the time axis of the data. These are required if |
None
|
x_label
|
str | None
|
Label to apply to the x-axis. If |
'time'
|
y_label
|
str | bool | None
|
Label to apply to the y-axis. If If |
True
|
warn_infer_y_label_with_multi_unit
|
bool
|
Should a warning be raised if we try to infer the y-unit but the data has more than one unit? |
True
|
observed
|
bool
|
Passed to pd.DataFrame.groupby. |
True
|
Returns:
| Type | Description |
|---|---|
PlumePlotter
|
Initialised instance |
Source code in src/pandas_openscm/plotting.py
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 | |
generate_legend_handles #
Generate handles for the legend
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quantile_legend_round
|
int
|
Rounding to apply to the quantiles when creating the label |
2
|
Returns:
| Type | Description |
|---|---|
list[Artist]
|
Generated handles for the legend |
Source code in src/pandas_openscm/plotting.py
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 | |
plot #
plot(
ax: Axes | None = None,
*,
create_legend: Callable[
[Axes, list[Artist]], None
] = create_legend_default,
quantile_legend_round: int = 2,
) -> Axes
Plot
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes | None
|
Axes onto which to plot |
None
|
create_legend
|
Callable[[Axes, list[Artist]], None]
|
Function to use to create the legend. This allows the user to have full control over the creation of the legend. |
create_legend_default
|
quantile_legend_round
|
int
|
Rounding to apply to quantile values when creating the legend |
2
|
Returns:
| Type | Description |
|---|---|
Axes
|
Axes on which the data was plotted |
Source code in src/pandas_openscm/plotting.py
SingleLinePlotter #
Object which is able to plot single lines
Methods:
| Name | Description |
|---|---|
get_label |
Get the label for the line |
plot |
Plot |
Attributes:
| Name | Type | Description |
|---|---|---|
alpha |
float
|
Alpha to use when plotting the line |
color |
COLOUR_VALUE_LIKE
|
Colour to use when plotting the line |
linestyle |
DASH_VALUE_LIKE
|
Style to use when plotting the line |
linewidth |
float
|
Linewidth to use when plotting the line |
pkwargs |
dict[str, Any] | None
|
Other arguments to pass to matplotlib.axes.Axes.plot when plotting |
quantile |
float
|
Quantile that this line represents |
x_vals |
NP_ARRAY_OF_FLOAT_OR_INT | PINT_NUMPY_ARRAY
|
x-values to plot |
y_vals |
NP_ARRAY_OF_FLOAT_OR_INT | PINT_NUMPY_ARRAY
|
y-values to plot |
Source code in src/pandas_openscm/plotting.py
pkwargs
class-attribute
instance-attribute
#
Other arguments to pass to matplotlib.axes.Axes.plot when plotting
y_vals
class-attribute
instance-attribute
#
y_vals: NP_ARRAY_OF_FLOAT_OR_INT | PINT_NUMPY_ARRAY = field(
validator=[same_shape_as_x_vals]
)
y-values to plot
get_label #
Get the label for the line
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quantile_legend_round
|
int
|
Rounding to apply to the quantile when creating the label |
2
|
Returns:
| Type | Description |
|---|---|
str
|
Label for the line |
Source code in src/pandas_openscm/plotting.py
plot #
Plot
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes on which to plot |
required |
quantile_legend_round
|
int
|
Rounding to apply to the quantile when creating the label |
2
|
Source code in src/pandas_openscm/plotting.py
SinglePlumePlotter #
Object which is able to plot single plumes
Methods:
| Name | Description |
|---|---|
get_label |
Get the label for the plume |
plot |
Plot |
Attributes:
| Name | Type | Description |
|---|---|---|
alpha |
float
|
Alpha to use when plotting the plume |
color |
COLOUR_VALUE_LIKE
|
Colour to use when plotting the plume |
pkwargs |
dict[str, Any] | None
|
Other arguments to pass to matplotlib.axes.Axes.fill_between when plotting |
quantiles |
tuple[float, float]
|
Quantiles that this plume represents |
x_vals |
NP_ARRAY_OF_FLOAT_OR_INT | PINT_NUMPY_ARRAY
|
x-values to plot |
y_vals_lower |
NP_ARRAY_OF_FLOAT_OR_INT | PINT_NUMPY_ARRAY
|
y-values to plot as the lower bound of the plume |
y_vals_upper |
NP_ARRAY_OF_FLOAT_OR_INT | PINT_NUMPY_ARRAY
|
y-values to plot as the upper bound of the plume |
Source code in src/pandas_openscm/plotting.py
pkwargs
class-attribute
instance-attribute
#
Other arguments to pass to matplotlib.axes.Axes.fill_between when plotting
y_vals_lower
class-attribute
instance-attribute
#
y_vals_lower: (
NP_ARRAY_OF_FLOAT_OR_INT | PINT_NUMPY_ARRAY
) = field(validator=[same_shape_as_x_vals])
y-values to plot as the lower bound of the plume
y_vals_upper
class-attribute
instance-attribute
#
y_vals_upper: (
NP_ARRAY_OF_FLOAT_OR_INT | PINT_NUMPY_ARRAY
) = field(validator=[same_shape_as_x_vals])
y-values to plot as the upper bound of the plume
get_label #
Get the label for the plume
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quantile_legend_round
|
int
|
Rounding to apply to the quantiles when creating the label |
2
|
Returns:
| Type | Description |
|---|---|
str
|
Label for the plume |
Source code in src/pandas_openscm/plotting.py
plot #
Plot
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes on which to plot |
required |
quantile_legend_round
|
int
|
Rounding to apply to the quantiles when creating the label |
2
|
Source code in src/pandas_openscm/plotting.py
create_legend_default #
Create legend, default implementation
Intended to be used with plot_plume_func
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes on which to create the legend |
required |
handles
|
list[Artist]
|
Handles to include in the legend |
required |
Source code in src/pandas_openscm/plotting.py
extract_single_unit #
Extract the unit of the data, expecting there to only be one unit
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
pd.DataFrame from which to get the unit |
required |
unit_var
|
str
|
Variable/column in the multi-index which holds unit information |
required |
Returns:
| Type | Description |
|---|---|
str
|
Unit of the data |
Raises:
| Type | Description |
|---|---|
AssertionError
|
The data has more than one unit |
Source code in src/pandas_openscm/plotting.py
fill_out_dashes #
fill_out_dashes(
style_values: Iterable[T],
dashes_user_supplied: dict[T, DASH_VALUE_LIKE] | None,
warn_on_value_missing: bool,
) -> dict[T, DASH_VALUE_LIKE]
Fill out dashes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
style_values
|
Iterable[T]
|
Values which require a value in the output dashes |
required |
dashes_user_supplied
|
dict[T, DASH_VALUE_LIKE] | None
|
User-supplied dashes |
required |
warn_on_value_missing
|
bool
|
Should a warning be emitted if |
required |
Returns:
| Type | Description |
|---|---|
dict[T, DASH_VALUE_LIKE]
|
Dashes with values for all |
Warns:
| Type | Description |
|---|---|
UserWarning
|
|
Source code in src/pandas_openscm/plotting.py
fill_out_palette #
fill_out_palette(
hue_values: Iterable[T],
palette_user_supplied: PALETTE_LIKE[T] | None,
warn_on_value_missing: bool,
) -> PALETTE_LIKE[T]
Fill out a palette
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hue_values
|
Iterable[T]
|
Values which require a value in the output palette |
required |
palette_user_supplied
|
PALETTE_LIKE[T] | None
|
User-supplied palette |
required |
warn_on_value_missing
|
bool
|
Should a warning be emitted if |
required |
Returns:
| Type | Description |
|---|---|
PALETTE_LIKE[T]
|
Palette with values for all |
Warns:
| Type | Description |
|---|---|
UserWarning
|
|
Source code in src/pandas_openscm/plotting.py
get_default_colour_cycler #
get_default_colour_cycler() -> Iterator[COLOUR_VALUE_LIKE]
Get the default colour cycler
Returns:
| Type | Description |
|---|---|
Iterator[COLOUR_VALUE_LIKE]
|
Default colour cycler |
Raises:
| Type | Description |
|---|---|
MissingOptionalDependencyError
|
matplotlib is not installed |
Source code in src/pandas_openscm/plotting.py
get_default_dash_cycler #
get_default_dash_cycler() -> Iterator[DASH_VALUE_LIKE]
get_pdf_from_pre_calculated #
get_pdf_from_pre_calculated(
in_df: DataFrame,
*,
quantiles: Iterable[float],
quantile_col: str,
) -> DataFrame
Get a pd.DataFrame for plotting from pre-calculated quantiles
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_df
|
DataFrame
|
Input pd.DataFrame |
required |
quantiles
|
Iterable[float]
|
Quantiles to grab |
required |
quantile_col
|
str
|
Name of the index column in which quantile information is stored |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame to use for plotting. |
Raises:
| Type | Description |
|---|---|
MissingQuantileError
|
One of the quantiles in |
Source code in src/pandas_openscm/plotting.py
get_quantiles #
get_quantiles(
quantiles_plumes: QUANTILES_PLUMES_LIKE,
) -> NDArray[floating[Any]]
Get just the quantiles from a QUANTILES_PLUMES_LIKE
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quantiles_plumes
|
QUANTILES_PLUMES_LIKE
|
Quantiles-plumes definition |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
Quantiles to be used in plotting |
Source code in src/pandas_openscm/plotting.py
get_values_line #
get_values_line(
pdf: DataFrame,
*,
unit_aware: Literal[False],
unit_var: str | None,
time_units: str | None,
) -> tuple[
NP_ARRAY_OF_FLOAT_OR_INT, NP_ARRAY_OF_FLOAT_OR_INT
]
get_values_line(
pdf: DataFrame,
*,
unit_aware: Literal[True] | UnitRegistry,
unit_var: str | None,
time_units: str | None,
) -> tuple[PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY]
get_values_line(
pdf: DataFrame,
*,
unit_aware: bool | UnitRegistry,
unit_var: str | None,
time_units: str | None,
) -> (
tuple[
NP_ARRAY_OF_FLOAT_OR_INT, NP_ARRAY_OF_FLOAT_OR_INT
]
| tuple[PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY]
)
get_values_line(
pdf: DataFrame,
*,
unit_aware: bool | UnitRegistry,
unit_var: str | None,
time_units: str | None,
) -> (
tuple[
NP_ARRAY_OF_FLOAT_OR_INT, NP_ARRAY_OF_FLOAT_OR_INT
]
| tuple[PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY]
)
Get values for plotting a line
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pdf
|
DataFrame
|
pd.DataFrame from which to get the values |
required |
unit_aware
|
bool | UnitRegistry
|
Should the values be unit-aware? If |
required |
unit_var
|
str | None
|
Variable/column in the multi-index which stores information about the unit of each timeseries. |
required |
time_units
|
str | None
|
Units of the time axis. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
x_values |
tuple[NP_ARRAY_OF_FLOAT_OR_INT, NP_ARRAY_OF_FLOAT_OR_INT] | tuple[PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY]
|
x-values (for a plot) |
y_values |
tuple[NP_ARRAY_OF_FLOAT_OR_INT, NP_ARRAY_OF_FLOAT_OR_INT] | tuple[PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY]
|
y-values (for a plot) |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
MissingOptionalDependencyError
|
|
Source code in src/pandas_openscm/plotting.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
get_values_plume #
get_values_plume(
pdf: DataFrame,
*,
quantiles: tuple[float, float],
quantile_var: str,
unit_aware: Literal[False],
unit_var: str | None,
time_units: str | None,
) -> tuple[
NP_ARRAY_OF_FLOAT_OR_INT,
NP_ARRAY_OF_FLOAT_OR_INT,
NP_ARRAY_OF_FLOAT_OR_INT,
]
get_values_plume(
pdf: DataFrame,
*,
quantiles: tuple[float, float],
quantile_var: str,
unit_aware: Literal[True] | UnitRegistry,
unit_var: str | None,
time_units: str | None,
) -> tuple[
PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY
]
get_values_plume(
pdf: DataFrame,
*,
quantiles: tuple[float, float],
quantile_var: str,
unit_aware: bool | UnitRegistry,
unit_var: str | None,
time_units: str | None,
) -> (
tuple[
NP_ARRAY_OF_FLOAT_OR_INT,
NP_ARRAY_OF_FLOAT_OR_INT,
NP_ARRAY_OF_FLOAT_OR_INT,
]
| tuple[
PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY
]
)
get_values_plume(
pdf: DataFrame,
*,
quantiles: tuple[float, float],
quantile_var: str,
unit_aware: bool | UnitRegistry,
unit_var: str | None,
time_units: str | None,
) -> (
tuple[
NP_ARRAY_OF_FLOAT_OR_INT,
NP_ARRAY_OF_FLOAT_OR_INT,
NP_ARRAY_OF_FLOAT_OR_INT,
]
| tuple[
PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY
]
)
Get values for plotting a line
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pdf
|
DataFrame
|
pd.DataFrame from which to get the values |
required |
quantiles
|
tuple[float, float]
|
Quantiles to get from |
required |
quantile_var
|
str
|
Variable/column in the multi-index which stores information about the quantile that each timeseries represents. |
required |
unit_aware
|
bool | UnitRegistry
|
Should the values be unit-aware? If |
required |
unit_var
|
str | None
|
Variable/column in the multi-index which stores information about the unit of each timeseries. |
required |
time_units
|
str | None
|
Units of the time axis. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
x_values |
tuple[NP_ARRAY_OF_FLOAT_OR_INT, NP_ARRAY_OF_FLOAT_OR_INT, NP_ARRAY_OF_FLOAT_OR_INT] | tuple[PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY]
|
x-values (for a plot) |
y_values_lower |
tuple[NP_ARRAY_OF_FLOAT_OR_INT, NP_ARRAY_OF_FLOAT_OR_INT, NP_ARRAY_OF_FLOAT_OR_INT] | tuple[PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY]
|
y-values for the lower-bound (of a plume plot) |
y_values_upper |
tuple[NP_ARRAY_OF_FLOAT_OR_INT, NP_ARRAY_OF_FLOAT_OR_INT, NP_ARRAY_OF_FLOAT_OR_INT] | tuple[PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY, PINT_NUMPY_ARRAY]
|
y-values for the upper-bound (of a plume plot) |
Raises:
| Type | Description |
|---|---|
TypeError
|
|
MissingOptionalDependencyError
|
|
Source code in src/pandas_openscm/plotting.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
plot_plume_after_calculating_quantiles_func #
plot_plume_after_calculating_quantiles_func(
pdf: DataFrame,
ax: Axes | None = None,
*,
quantile_over: str | list[str],
quantiles_plumes: QUANTILES_PLUMES_LIKE = (
(0.5, 0.7),
((0.05, 0.95), 0.2),
),
quantile_var_label: str | None = None,
quantile_legend_round: int = 2,
hue_var: str = "scenario",
hue_var_label: str | None = None,
palette: PALETTE_LIKE[Any] | None = None,
warn_on_palette_value_missing: bool = True,
style_var: str = "variable",
style_var_label: str | None = None,
dashes: dict[Any, str | tuple[float, tuple[float, ...]]]
| None = None,
warn_on_dashes_value_missing: bool = True,
linewidth: float = 3.0,
unit_var: str = "unit",
unit_aware: bool | UnitRegistry = False,
time_units: str | None = None,
x_label: str | None = "time",
y_label: str | bool | None = True,
warn_infer_y_label_with_multi_unit: bool = True,
create_legend: Callable[
[Axes, list[Artist]], None
] = create_legend_default,
observed: bool = True,
) -> Axes
Plot a plume plot, calculating the required quantiles first
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pdf
|
DataFrame
|
pd.DataFrame to use for plotting It must contain quantiles already. For data without quantiles, please see plot_plume_after_calculating_quantiles_func. |
required |
ax
|
Axes | None
|
Axes on which to plot. If not supplied, a new axes is created. |
None
|
quantile_over
|
str | list[str]
|
Variable(s)/column(s) over which to calculate the quantiles. The data is grouped by all columns except |
required |
quantiles_plumes
|
QUANTILES_PLUMES_LIKE
|
Quantiles to plot in each plume. If the first element of each tuple is a tuple, a plume is plotted between the given quantiles. Otherwise, if the first element is a plain float, a line is plotted for the given quantile. |
((0.5, 0.7), ((0.05, 0.95), 0.2))
|
quantile_var_label
|
str | None
|
Label to use as the header for the quantile section in the legend |
None
|
quantile_legend_round
|
int
|
Rounding to apply to quantile values when creating the legend |
2
|
hue_var
|
str
|
Variable to use for grouping data into different colour groups |
'scenario'
|
hue_var_label
|
str | None
|
Label to use as the header for the hue/colour section in the legend |
None
|
palette
|
PALETTE_LIKE[Any] | None
|
Colour to use for the different groups in the data. If any groups are not included in |
None
|
warn_on_palette_value_missing
|
bool
|
Should a warning be emitted if there are values missing from |
True
|
style_var
|
str
|
Variable to use for grouping data into different (line)style groups |
'variable'
|
style_var_label
|
str | None
|
Label to use as the header for the style section in the legend |
None
|
dashes
|
dict[Any, str | tuple[float, tuple[float, ...]]] | None
|
Dash/linestyle to use for the different groups in the data. If any groups are not included in |
None
|
warn_on_dashes_value_missing
|
bool
|
Should a warning be emitted if there are values missing from |
True
|
linewidth
|
float
|
Width to use for plotting lines. |
3.0
|
unit_var
|
str
|
Variable/column in the multi-index which stores information about the unit of each timeseries. |
'unit'
|
unit_aware
|
bool | UnitRegistry
|
Should the plot be done in a unit-aware way? If For details, see matplotlib and pint support plotting with units (stable docs, last version that we checked at the time of writing). |
False
|
time_units
|
str | None
|
Units of the time axis. These are required if |
None
|
x_label
|
str | None
|
Label to apply to the x-axis. If |
'time'
|
y_label
|
str | bool | None
|
Label to apply to the y-axis. If If |
True
|
warn_infer_y_label_with_multi_unit
|
bool
|
Should a warning be raised if we try to infer the y-unit but the data has more than one unit? |
True
|
create_legend
|
Callable[[Axes, list[Artist]], None]
|
Function to use to create the legend. This allows the user to have full control over the creation of the legend. |
create_legend_default
|
observed
|
bool
|
Passed to pd.DataFrame.groupby. |
True
|
Returns:
| Type | Description |
|---|---|
Axes
|
Axes on which the data was plotted |
Source code in src/pandas_openscm/plotting.py
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 | |
plot_plume_func #
plot_plume_func(
pdf: DataFrame,
quantiles_plumes: QUANTILES_PLUMES_LIKE,
ax: Axes | None = None,
*,
quantile_var: str = "quantile",
quantile_var_label: str | None = None,
quantile_legend_round: int = 3,
hue_var: str = "scenario",
hue_var_label: str | None = None,
palette: PALETTE_LIKE[Any] | None = None,
warn_on_palette_value_missing: bool = True,
style_var: str = "variable",
style_var_label: str | None = None,
dashes: dict[Any, str | tuple[float, tuple[float, ...]]]
| None = None,
warn_on_dashes_value_missing: bool = True,
linewidth: float = 2.0,
unit_var: str = "unit",
unit_aware: bool | UnitRegistry = False,
time_units: str | None = None,
x_label: str | None = "time",
y_label: str | bool | None = True,
warn_infer_y_label_with_multi_unit: bool = True,
create_legend: Callable[
[Axes, list[Artist]], None
] = create_legend_default,
observed: bool = True,
) -> Axes
Plot a plume plot
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pdf
|
DataFrame
|
pd.DataFrame to use for plotting It must contain quantiles already. For data without quantiles, please see plot_plume_after_calculating_quantiles_func. |
required |
quantiles_plumes
|
QUANTILES_PLUMES_LIKE
|
Quantiles to plot in each plume. If the first element of each tuple is a tuple, a plume is plotted between the given quantiles. Otherwise, if the first element is a plain float, a line is plotted for the given quantile. |
required |
ax
|
Axes | None
|
Axes on which to plot. If not supplied, a new axes is created. |
None
|
quantile_var
|
str
|
Variable/column in the multi-index which stores information about the quantile that each timeseries represents. |
'quantile'
|
quantile_var_label
|
str | None
|
Label to use as the header for the quantile section in the legend |
None
|
quantile_legend_round
|
int
|
Rounding to apply to quantile values when creating the legend |
3
|
hue_var
|
str
|
Variable to use for grouping data into different colour groups |
'scenario'
|
hue_var_label
|
str | None
|
Label to use as the header for the hue/colour section in the legend |
None
|
palette
|
PALETTE_LIKE[Any] | None
|
Colour to use for the different groups in the data. If any groups are not included in |
None
|
warn_on_palette_value_missing
|
bool
|
Should a warning be emitted if there are values missing from |
True
|
style_var
|
str
|
Variable to use for grouping data into different (line)style groups |
'variable'
|
style_var_label
|
str | None
|
Label to use as the header for the style section in the legend |
None
|
dashes
|
dict[Any, str | tuple[float, tuple[float, ...]]] | None
|
Dash/linestyle to use for the different groups in the data. If any groups are not included in |
None
|
warn_on_dashes_value_missing
|
bool
|
Should a warning be emitted if there are values missing from |
True
|
linewidth
|
float
|
Width to use for plotting lines. |
2.0
|
unit_var
|
str
|
Variable/column in the multi-index which stores information about the unit of each timeseries. |
'unit'
|
unit_aware
|
bool | UnitRegistry
|
Should the plot be done in a unit-aware way? If For details, see matplotlib and pint support plotting with units (stable docs, last version that we checked at the time of writing). |
False
|
time_units
|
str | None
|
Units of the time axis of the data. These are required if |
None
|
x_label
|
str | None
|
Label to apply to the x-axis. If |
'time'
|
y_label
|
str | bool | None
|
Label to apply to the y-axis. If If |
True
|
warn_infer_y_label_with_multi_unit
|
bool
|
Should a warning be raised if we try to infer the y-unit but the data has more than one unit? |
True
|
create_legend
|
Callable[[Axes, list[Artist]], None]
|
Function to use to create the legend. This allows the user to have full control over the creation of the legend. |
create_legend_default
|
observed
|
bool
|
Passed to pd.DataFrame.groupby. |
True
|
Returns:
| Type | Description |
|---|---|
Axes
|
Axes on which the data was plotted |
Source code in src/pandas_openscm/plotting.py
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 | |
same_shape_as_x_vals #
same_shape_as_x_vals(
obj: SingleLinePlotter | SinglePlumePlotter,
attribute: Attribute[Any],
value: NP_ARRAY_OF_FLOAT_OR_INT | PINT_NUMPY_ARRAY,
) -> None
Validate that the received values are the same shape as obj.x_vals
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
SingleLinePlotter | SinglePlumePlotter
|
Object on which we are peforming validation |
required |
attribute
|
Attribute[Any]
|
Attribute which is being set |
required |
value
|
NP_ARRAY_OF_FLOAT_OR_INT | PINT_NUMPY_ARRAY
|
Value which is being used to set |
required |
Raises:
| Type | Description |
|---|---|
AssertionError
|
|