PeterRochford / SkillMetrics

A Python library for calculating and displaying the skill of model predictions against observations.
GNU General Public License v3.0
201 stars 92 forks source link

custom control marker color #47

Open lybdzxy opened 7 months ago

lybdzxy commented 7 months ago

When I try to custom control marker color like this:

MARKERS = {
"EC-Earth3": {
        "labelColor": "k",
        "symbol": "+",
        "size": 9,
        "faceColor": "#b4ddd4",
        "edgeColor": "#b4ddd4"
}
}

The following error occurred:

Traceback (most recent call last):
  File "E:\GEO\pyproject\taylor_dia.py", line 137, in <module>
    sm.taylor_diagram(sdev, crmsd, ccoef, markers=MARKERS, markerLegend='on',labelrms= 'RMSE')
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\skill_metrics\taylor_diagram.py", line 388, in taylor_diagram
    plot_pattern_diagram_markers(ax, X, Y, options)
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\skill_metrics\plot_pattern_diagram_markers.py", line 107, in plot_pattern_diagram_markers
    h = ax.plot(X[i],Y[i],marker[i], markersize = markersize[i],
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\matplotlib\axes\_axes.py", line 1662, in plot
    lines = [*self._get_lines(*args, data=data, **kwargs)]
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\matplotlib\axes\_base.py", line 311, in __call__
    yield from self._plot_args(
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\matplotlib\axes\_base.py", line 454, in _plot_args
    linestyle, marker, color = _process_plot_format(
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\matplotlib\axes\_base.py", line 197, in _process_plot_format
    raise ValueError(
ValueError: '+#b4ddd4' is not a valid format string (unrecognized character '#')

I finaly found the solution: the code in get_single_markers.py in line 43:

    # Iterate through keys in dictionary
    for key in markers:
        color = markers[key]['faceColor']
        symbol = markers[key]['symbol']
        SymbolColor = symbol + color
        marker.append(SymbolColor)
        markersize.append(markers[key]['size'])
        markerfacecolor.append(color)
        markeredgecolor.append(markers[key]['edgeColor'])
        markerlabel.append(key) # store label
        labelcolor.append(markers[key]['labelColor'])

should change into:

     # Iterate through keys in dictionary
    for key in markers:
        color = markers[key]['faceColor']
        symbol = markers[key]['symbol']
        marker.append(symbol)
        markersize.append(markers[key]['size'])
        markerfacecolor.append(color)
        markeredgecolor.append(markers[key]['edgeColor'])
        markerlabel.append(key) # store label
        labelcolor.append(markers[key]['labelColor'])

because it seems that matplotlib only suport symbol + color in 1 letter (eg: 'or','xg',etc)