Skip to content

Commit

Permalink
ENH: updated DistributionDisplay Scatter/Violin names, examples (#690)
Browse files Browse the repository at this point in the history
* ENH: updated scatter/violin plotting routines names, examples

* ENH: Update to scatter naming convention

---------

Co-authored-by: zssherman <[email protected]>
  • Loading branch information
jrobrien91 and zssherman authored Jun 20, 2023
1 parent 892cd14 commit 1fe4571
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 47 deletions.
45 changes: 22 additions & 23 deletions act/plotting/distributiondisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,17 +638,16 @@ def set_ratio_line(self, subplot_index=(0, )):
ratio = np.linspace(xlims[0], xlims[-1])
self.axes[subplot_index].plot(ratio, ratio, 'k--')

def scatter(
self,
x_field,
y_field,
m_field=None,
dsname=None,
cbar_label=None,
set_title=None,
subplot_index=(0,),
**kwargs,
):
def plot_scatter(self,
x_field,
y_field,
m_field=None,
dsname=None,
cbar_label=None,
set_title=None,
subplot_index=(0,),
**kwargs,
):
"""
This procedure will produce a scatter plot from 2 variables.
Expand Down Expand Up @@ -755,18 +754,18 @@ def scatter(

return self.axes[subplot_index]

def violin(self,
field,
positions=None,
dsname=None,
vert=True,
showmeans=True,
showmedians=True,
showextrema=True,
subplot_index=(0,),
set_title=None,
**kwargs,
):
def plot_violin(self,
field,
positions=None,
dsname=None,
vert=True,
showmeans=True,
showmedians=True,
showextrema=True,
subplot_index=(0,),
set_title=None,
**kwargs,
):
"""
This procedure will produce a violin plot for the selected
field (or fields).
Expand Down
18 changes: 9 additions & 9 deletions act/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,10 +1251,10 @@ def test_violin():
display = DistributionDisplay(ds)

# Create violin display of mean temperature
display.violin('temp_mean',
positions=[5.0],
set_title='SGP MET E13 2019-01-01'
)
display.plot_violin('temp_mean',
positions=[5.0],
set_title='SGP MET E13 2019-01-01'
)

ds.close()

Expand All @@ -1267,11 +1267,11 @@ def test_scatter():
# Create a DistributionDisplay object to compare fields
display = DistributionDisplay(ds)

display.scatter('wspd_arith_mean',
'wspd_vec_mean',
m_field='wdir_vec_mean',
marker='d',
cmap='bwr')
display.plot_scatter('wspd_arith_mean',
'wspd_vec_mean',
m_field='wdir_vec_mean',
marker='d',
cmap='bwr')
# Set the range of the field on the x-axis
display.set_xrng((0, 14))
display.set_yrng((0, 14))
Expand Down
2 changes: 1 addition & 1 deletion examples/plotting/plot_heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@

# Plot the scatter plot and shade by wind_speed
title = 'Scatter plot of MET RH vs Temp'
display.scatter('temp_mean', 'rh_mean', subplot_index=(0, 1), set_title=title, m_field='time')
display.plot_scatter('temp_mean', 'rh_mean', subplot_index=(0, 1), set_title=title, m_field='time')

plt.show()
56 changes: 50 additions & 6 deletions examples/plotting/plot_scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"""

import act
import numpy as np

from scipy.stats.mstats import pearsonr
from act.io.icartt import read_icartt

# Call the read_icartt function, which supports input
Expand All @@ -22,15 +24,57 @@
display = act.plotting.DistributionDisplay(ds)

# Compare aircraft ground speed with indicated airspeed
display.scatter('true_airspeed',
'ground_speed',
m_field='ambient_temp',
marker='x',
cbar_label='Ambient Temperature ($^\circ$C)'
)
display.plot_scatter('true_airspeed',
'ground_speed',
m_field='ambient_temp',
marker='x',
cbar_label='Ambient Temperature ($^\circ$C)'
)

# Set the range of the field on the x-axis
display.set_xrng((40, 140))
display.set_yrng((40, 140))

# Determine the best fit line
z = np.ma.polyfit(ds['true_airspeed'],
ds['ground_speed'],
1
)
p = np.poly1d(z)

# Plot the best fit line
display.axes[0].plot(ds['true_airspeed'],
p(ds['true_airspeed']),
'r',
linewidth=2
)

# Display the line equation
display.axes[0].text(45,
135,
"y = %.3fx + (%.3f)" % (z[0], z[1]),
color='r',
fontsize=12
)

# Calculate Pearson Correlation Coefficient
cc_conc = pearsonr(ds['true_airspeed'],
ds['ground_speed']
)

# Display the Pearson CC
display.axes[0].text(45,
130,
"Pearson CC: %.2f" % (cc_conc[0]),
fontsize=12
)

# Display the total number of samples
display.axes[0].text(45,
125,
"N = %.0f" % (ds['true_airspeed'].data.shape[0]),
fontsize=12
)

# Display the 1:1 ratio line
display.set_ratio_line()
18 changes: 10 additions & 8 deletions examples/plotting/plot_violin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Investigate Temperature Quantiles
with Violin Plots
---------------------------------
Investigate temperature quantiles using
Expand All @@ -23,14 +24,15 @@
display = act.plotting.DistributionDisplay(ds)

# Compare aircraft ground speed with ambient temperature
display.violin('ambient_temp',
positions=[1.0],
)

display.violin('total_temp',
positions=[2.0],
set_title='Aircraft Temperatures 2018-11-04',
)
display.plot_violin('ambient_temp',
positions=[1.0],
)

display.plot_violin('total_temp',
positions=[2.0],
set_title='Aircraft Temperatures 2018-11-04',
)

# Update the tick information
display.axes[0].set_xticks([0.5, 1, 2, 2.5])
display.axes[0].set_xticklabels(['',
Expand Down

0 comments on commit 1fe4571

Please sign in to comment.