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

Plot taylor_diagram inside subplots #22

Closed ashesh-0 closed 2 years ago

ashesh-0 commented 4 years ago

Hello, I was looking to plot the taylor diagram inside matplotlib's subplots. Something like:

thresholds = [-1, 1, 2, 5, 10, 20, 30]
_,ax = plt.subplots(figsize=(3*len(thresholds), 3), ncols=len(thresholds))

for i, threshold in enumerate(thresholds):
    mask = tar > threshold
    stats = sm.taylor_statistics(pred[mask], tar[mask])
    sdev = np.array([stats['sdev'][0], stats['sdev'][1]])
    crmsd = np.array([stats['crmsd'][0], stats['crmsd'][1],])                     
    ccoef = np.array([stats['ccoef'][0], stats['ccoef'][1]])

    sm.taylor_diagram(sdev,crmsd,ccoef,markerLabel=['Target','Pred'],markerLegend='on', ax=ax[i])
plt.show()

I don't see taylor_diagram supporting ax arguement. Do let me know if there is already some (even hacky) way to do this. Thanks !!

pierreloicq commented 3 years ago

For people of the future: It worked for me, you need something like this in your loop: ax[rowIndexInYourSubplot, colIndexInYourSubplot] = plt.subplot( numberOfRows, numberOfCols, posOfCurrentSubplot ) Maybe it works also with a "one index" subplot (only 1 row or 1 col), cfr subplot doc

PeterRochford commented 2 years ago

The capability to plot target and taylor diagrams inside matplotlib's subplots is now available in SkillMetrics 1.2.1 (released 9/5/2022). Refer to the following examples that use this capability:

Target Diagram Example 9 Taylor Diagram Example 14

collinsowusu commented 2 years ago

"pip install SkillMetrics --upgrade" doesn't install the latest update (1.2.1). It still installs version 1.1.8

I tried specifying the version to install but got this error: "No matching distribution found for SkillMetrics==1.2.1"

PeterRochford commented 2 years ago

Collins,

The latest version of SkillMetrics only supports Python 3. Try the following command instead:

pip3 install SkillMetrics --upgrade

It works fine for me in installing version 1.2.1. I have updated the documentation on the Wiki home https://github.com/PeterRochford/SkillMetrics/wiki page accordingly.

The project description on the PyPI page will not get updated until I post a new release.

Peter Rochford

On Sep 7, 2022, at 2:33 AM, Collins Owusu @.***> wrote:

"pip install SkillMetrics --upgrade" doesn't install the latest update (1.2.1). It still installs version 1.1.8

I tried specifying the version to install but got this error: "No matching distribution found for SkillMetrics==1.2.1"

— Reply to this email directly, view it on GitHub https://github.com/PeterRochford/SkillMetrics/issues/22#issuecomment-1238965643, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF3YS7F4GYOIBOGLTCME7E3V5AZKBANCNFSM4TAEZVMA. You are receiving this because you commented.

collinsowusu commented 2 years ago

Hello Peter,

I use Python 3. I have uninstalled the previous version and even purged pip's cache but it still installs version 1.1.8.

Below is the results of my installation process: image

PeterRochford commented 2 years ago

Perhaps there is a conflict with anaconda3 which you appear to have installed on your computer. I don't use anaconda, but according to my internet search you need to start anaconda and then install from within that environment. The steps appear to be:

  1. Open Anaconda Command prompt as administrator
  2. pip install SkillMetrics

I hope this helps.

collinsowusu commented 2 years ago

Hello Peter,

Thanks for your help. I installed it within my working environment but it didn't resolve the problem.

I downloaded the SkillMetrics code from the repository and imported it directly, which works for me.

I still don't know why the pip install is not working for me.

PeterRochford commented 2 years ago

Thank you for the update. Since you've solved your problem I will now close this issue.

ogunjosam commented 2 years ago

Hello Peter,

Thanks for your help. I installed it within my working environment but it didn't resolve the problem.

I downloaded the SkillMetrics code from the repository and imported it directly, which works for me.

I still don't know why the pip install is not working for me.

Hello @collinsowusu ,

I am currently having the same issue with installing SkillMetrics -1.2.1 using Google Colab. Can you share the process of downloading and importing the code directly?

All attempts to install version 1.2.1 failed.

Thank you.

collinsowusu commented 2 years ago

Hello @ogunjosam,

Open the SkillMetrics code repository and download the code as zip. Unzip and copy the skill_metrics folder to the location of your code.

You can then do: "import skill_metrics as sm" Python will first look at the package folder at your code location before it will search in any other location on your computer so it will import the from the folder you downloaded.

Collins

ogunjosam commented 2 years ago

Hello @ogunjosam,

Open the SkillMetrics code repository and download the code as zip. Unzip and copy the skill_metrics folder to the location of your code.

You can then do: "import skill_metrics as sm" Python will first look at the package folder at your code location before it will search in any other location on your computer so it will import the from the folder you downloaded.

Collins

Thank you so much.

PeterRochford commented 2 years ago

@collinsowusu: Thank you for posting a solution. I've added it to the FAQ under Installation Issues as Q2.