diff --git a/act/plotting/distributiondisplay.py b/act/plotting/distributiondisplay.py index 4c3c0f7df7..92baa94ff4 100644 --- a/act/plotting/distributiondisplay.py +++ b/act/plotting/distributiondisplay.py @@ -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. @@ -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). diff --git a/act/tests/test_plotting.py b/act/tests/test_plotting.py index 0f3622b336..2a5042ec8c 100644 --- a/act/tests/test_plotting.py +++ b/act/tests/test_plotting.py @@ -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() @@ -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)) diff --git a/examples/plotting/plot_heatmap.py b/examples/plotting/plot_heatmap.py index 5b3b0f89d9..a3996d06c9 100644 --- a/examples/plotting/plot_heatmap.py +++ b/examples/plotting/plot_heatmap.py @@ -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() diff --git a/examples/plotting/plot_scatter.py b/examples/plotting/plot_scatter.py index 03d2a9dc86..c221e49728 100644 --- a/examples/plotting/plot_scatter.py +++ b/examples/plotting/plot_scatter.py @@ -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 @@ -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() diff --git a/examples/plotting/plot_violin.py b/examples/plotting/plot_violin.py index afde31dd38..fc5b938fa9 100644 --- a/examples/plotting/plot_violin.py +++ b/examples/plotting/plot_violin.py @@ -1,5 +1,6 @@ """ Investigate Temperature Quantiles +with Violin Plots --------------------------------- Investigate temperature quantiles using @@ -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(['',