Skip to content

Commit 1846fe6

Browse files
committed
Plot only one contour color map
Use thick lines for the "main" and thin lines for the "ref".
1 parent 01312f7 commit 1846fe6

File tree

3 files changed

+43
-46
lines changed

3 files changed

+43
-46
lines changed

mpas_analysis/default.cfg

+5-1
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,7 @@ compareAsContoursOnSinglePlot = False
23732373

23742374
# the line width to use for contours on heatmaps and for
23752375
# contours of the model field on contour comparison plots
2376-
contourLineWidth = 1
2376+
contourLineWidth = 2
23772377

23782378
# the line style to use for contours on heatmaps and for
23792379
# contours of the model field on contour comparison plots
@@ -2383,6 +2383,10 @@ contourLineStyle = solid
23832383
# contours of the model field on contour comparison plots
23842384
contourLineColor = black
23852385

2386+
# the line width to use for observation or reference model contours in a
2387+
# contour comparison plots
2388+
comparisonContourLineWidth = 1
2389+
23862390
# the line style to use for contours of the reference field
23872391
# on contour comparison plots
23882392
comparisonContourLineStyle = solid

mpas_analysis/ocean/plot_transect_subtask.py

+9-15
Original file line numberDiff line numberDiff line change
@@ -525,25 +525,26 @@ def _plot_transect(self, remappedModelClimatology, remappedRefClimatology):
525525
compareAsContours = config.getboolean(
526526
'transects', 'compareAsContoursOnSinglePlot')
527527

528-
contourLineWidth = config.getint('transects', 'contourLineWidth')
528+
contourLineWidth = config.getfloat('transects', 'contourLineWidth')
529529
contourLineStyle = config.get('transects', 'contourLineStyle')
530530
comparisonContourLineStyle = config.get('transects',
531531
'comparisonContourLineStyle')
532532

533533
if compareAsContours:
534534
contourLineColor = None
535535
comparisonContourLineColor = None
536-
contourColormap, comparisonContourColormap = \
537-
PlotTransectSubtask._get_contour_colormaps()
536+
contourColormap = PlotTransectSubtask._get_contour_colormap()
538537
labelContours = config.getboolean(
539538
'transects', 'labelContoursOnContourComparisonPlots')
539+
comparisonContourLineWidth = \
540+
config.getfloat('transects', 'comparisonContourLineWidth')
540541
else:
541542
contourLineColor = config.get('transects', 'contourLineColor')
542543
comparisonContourLineColor = None
543544
contourColormap = None
544-
comparisonContourColormap = None
545545
labelContours = config.getboolean('transects',
546546
'labelContoursOnHeatmaps')
547+
comparisonContourLineWidth = None
547548

548549
contourLabelPrecision = config.getint('transects',
549550
'contourLabelPrecision')
@@ -596,9 +597,9 @@ def _plot_transect(self, remappedModelClimatology, remappedRefClimatology):
596597
lineStyle=contourLineStyle,
597598
lineColor=contourLineColor,
598599
contourColormap=contourColormap,
600+
comparisonContourLineWidth=comparisonContourLineWidth,
599601
comparisonContourLineStyle=comparisonContourLineStyle,
600602
comparisonContourLineColor=comparisonContourLineColor,
601-
comparisonContourColormap=comparisonContourColormap,
602603
labelContours=labelContours,
603604
contourLabelPrecision=contourLabelPrecision,
604605
plotTitleFontSize=titleFontSize,
@@ -854,18 +855,11 @@ def _get_ds_triangulation(self, dsTransectTriangles):
854855
return triangulation_args
855856

856857
@staticmethod
857-
def _get_contour_colormaps():
858+
def _get_contour_colormap():
858859
# https://stackoverflow.com/a/18926541/7728169
859860

860-
cmap = cm.get_cmap('cmo.haline')
861-
x = numpy.linspace(0., 1., 100)
862-
# passes through 0 and 1, but slowly at 0 and fast at 1 to minimize
863-
# the yellow, which is also in the "hot" colormap
864-
main_cmap = colors.LinearSegmentedColormap.from_list(
865-
f'trunc_{cmap.name}', cmap(x**1.2))
866-
867861
cmap = cm.get_cmap('hot')
868-
ref_cmap = colors.LinearSegmentedColormap.from_list(
862+
cmap = colors.LinearSegmentedColormap.from_list(
869863
f'trunc_{cmap.name}', cmap(numpy.linspace(0.1, 0.85, 100)))
870864

871-
return main_cmap, ref_cmap
865+
return cmap

mpas_analysis/shared/plot/vertical_section.py

+29-30
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ def plot_vertical_section_comparison(
7777
maxXTicks=20,
7878
calendar='gregorian',
7979
compareAsContours=False,
80+
comparisonContourLineWidth=None,
8081
comparisonContourLineStyle=None,
8182
comparisonContourLineColor=None,
82-
comparisonContourColormap=None,
8383
labelContours=False,
8484
contourLabelPrecision=1,
8585
resultSuffix='Result',
@@ -189,7 +189,7 @@ def plot_vertical_section_comparison(
189189
the number of dots per inch of the figure, taken from section ``plot``
190190
option ``dpi`` in the config file by default
191191
192-
lineWidth : int, optional
192+
lineWidth : float, optional
193193
the line width of contour lines (if specified)
194194
195195
lineStyle : str, optional
@@ -273,6 +273,10 @@ def plot_vertical_section_comparison(
273273
refArray is None, in which case only the contours of modelArray will be
274274
plotted on the single panel plot).
275275
276+
comparisonContourLineWidth : float, optional
277+
the line width of contour lines of the comparisonFieldName field on
278+
a contour comparison plot
279+
276280
comparisonContourLineStyle : str, optional
277281
the line style of contour lines of the reference field on a contour
278282
comparison plot
@@ -337,15 +341,15 @@ def plot_vertical_section_comparison(
337341
# depending on how many x axes are to be displayed on the plots
338342
if singlePanel:
339343
if compareAsContours and refArray is not None and \
340-
contourColormap is None and \
341-
comparisonContourColormap is None:
344+
contourColormap is None:
342345
# no color bar but there is a legend at the bottom
343346
if len(xCoords) == 3:
344347
figsize = (8, 8)
345348
else:
346349
figsize = (8, 7)
347350
else:
348-
figsize = (8, 5)
351+
# color bar and legend
352+
figsize = (8, 7)
349353
elif len(xCoords) == 3:
350354
figsize = (8, 17)
351355
else:
@@ -436,9 +440,9 @@ def plot_vertical_section_comparison(
436440
contourComparisonField=contourComparisonField,
437441
comparisonFieldName=comparisonFieldName,
438442
originalFieldName=originalFieldName,
443+
comparisonContourLineWidth=comparisonContourLineWidth,
439444
comparisonContourLineStyle=comparisonContourLineStyle,
440445
comparisonContourLineColor=comparisonContourLineColor,
441-
comparisonContourColormap=comparisonContourColormap,
442446
labelContours=labelContours,
443447
contourLabelPrecision=contourLabelPrecision,
444448
maxTitleLength=maxTitleLength)
@@ -585,9 +589,9 @@ def plot_vertical_section(
585589
contourComparisonField=None,
586590
comparisonFieldName=None,
587591
originalFieldName=None,
592+
comparisonContourLineWidth=None,
588593
comparisonContourLineStyle=None,
589594
comparisonContourLineColor=None,
590-
comparisonContourColormap=None,
591595
labelContours=False,
592596
contourLabelPrecision=1,
593597
maxTitleLength=70):
@@ -694,7 +698,7 @@ def plot_vertical_section(
694698
yLim : float array, optional
695699
y range of plot
696700
697-
lineWidth : int, optional
701+
lineWidth : float, optional
698702
the line width of contour lines (if specified)
699703
700704
lineStyle : str, optional
@@ -789,6 +793,10 @@ def plot_vertical_section(
789793
contours on a contour comparison plot). If contourComparisonField
790794
is None, this parameter is ignored.
791795
796+
comparisonContourLineWidth : float, optional
797+
the line width of contour lines of the comparisonFieldName field on
798+
a contour comparison plot
799+
792800
comparisonContourLineStyle : str, optional
793801
the line style of contour lines of the comparisonFieldName field on
794802
a contour comparison plot
@@ -975,19 +983,26 @@ def plot_vertical_section(
975983
plt.clabel(cs1, fmt=fmt_string)
976984

977985
if plotAsContours and contourComparisonField is not None:
986+
if comparisonContourLineWidth is None:
987+
comparisonContourLineWidth = lineWidth
978988
cs2 = plt.tricontour(maskedComparisonTriangulation,
979989
contourComparisonField.values.ravel(),
980990
levels=contourLevels,
981991
colors=comparisonContourLineColor,
982992
linestyles=comparisonContourLineStyle,
983-
linewidths=lineWidth,
984-
cmap=comparisonContourColormap)
993+
linewidths=comparisonContourLineWidth,
994+
cmap=contourColormap)
985995

986996
if labelContours:
987997
plt.clabel(cs2, fmt=fmt_string)
988998

989-
if plotAsContours and contourComparisonField is not None and \
990-
lineColor is not None and comparisonContourLineColor is not None:
999+
plotLegend = (((lineColor is not None and
1000+
comparisonContourLineColor is not None) or
1001+
(lineWidth is not None and
1002+
comparisonContourLineWidth is not None)) and
1003+
(plotAsContours and contourComparisonField is not None))
1004+
1005+
if plotLegend:
9911006
h1, _ = cs1.legend_elements()
9921007
h2, _ = cs2.legend_elements()
9931008
if labelContours:
@@ -1043,29 +1058,13 @@ def plot_vertical_section(
10431058
yearStride=yearStrideXTicks)
10441059

10451060
if contourLevels is not None:
1046-
if plotAsContours and contourComparisonField is not None and \
1047-
comparisonContourColormap is not None:
1048-
cbar2 = fig.colorbar(cs2, ax=ax, fraction=.05,
1049-
orientation='vertical',
1050-
spacing='proportional')
1051-
if colorbarLabel is None:
1052-
cbar2.set_label(comparisonFieldName)
1053-
else:
1054-
cbar2.set_label(f'{comparisonFieldName} ({colorbarLabel})')
1055-
10561061
if contourColormap is not None:
10571062
cbar1 = fig.colorbar(cs1, ax=ax, fraction=.05,
10581063
orientation='vertical',
10591064
spacing='proportional')
10601065

1061-
if contourComparisonField is None:
1062-
if colorbarLabel is None:
1063-
cbar1.set_label(originalFieldName)
1064-
else:
1065-
cbar1.set_label(f'{originalFieldName} ({colorbarLabel})')
1066-
else:
1067-
cbar1.ax.set_yticklabels([])
1068-
cbar1.set_label(originalFieldName)
1066+
if colorbarLabel is not None:
1067+
cbar1.set_label(colorbarLabel)
10691068

10701069
# add a second x-axis scale, if it was requested
10711070
if xCoords is not None and len(xCoords) >= 2:

0 commit comments

Comments
 (0)