<jupyter_start><jupyter_text>matplotlib scatter<jupyter_code>plt.scatter(data=fuel_econ, x='displ', y='comb')
plt.xlabel('Displacement (1)')
plt.ylabel('Combined Fuel Eff. (mpg)');<jupyter_output><empty_output><jupyter_text>seaborn scatter<jupyter_code>sns.regplot(data=fuel_econ, x = 'displ', y = 'comb')
plt.xlabel('Displacement (1)')
plt.ylabel('Combined Fuel Eff. (mpg)');<jupyter_output><empty_output><jupyter_text>plot regression line on transformed data<jupyter_code>def log_trans(x, inverse = False):
    if not inverse:
        return np.log10(x)
    else:
        return np.power(10,x)
    
#sns.regplot(fuel_econ['displ'], fuel_econ['comb'].apply(log_trans))
sns.regplot(data=fuel_econ, x=fuel_econ['displ'], y=fuel_econ['comb'].apply(log_trans))
tick_locs = [10,20,50,100]
plt.yticks( log_trans (tick_locs),  tick_locs);<jupyter_output><empty_output><jupyter_text>Jitter<jupyter_code>plt.figure(figsize=[20,5])
plt.subplot(1,2,1)
sns.regplot(data=fuel_econ, x = 'year', y = 'comb', truncate=False)

plt.subplot(1,2,2)
# In the sb.regplot() function below, the `truncate` argument accepts a boolean.
# If truncate=True, the regression line is bounded by the data limits. 
# Else if truncate=False, it extends to the x axis limits.
# The x_jitter will make each x value will be adjusted randomly by +/-0.3
sns.regplot(data = fuel_econ, x = 'year', y = 'comb', truncate=False, x_jitter=0.3);<jupyter_output><empty_output><jupyter_text>Transparency<jupyter_code># The scatter_kws helps specifying the opaqueness of the data points. 
# The alpha take a value between [0-1], where 0 represents transparent, and 1 is opaque. 
sns.regplot(data = fuel_econ, x = 'year', y = 'comb', truncate=False, x_jitter=0.3, scatter_kws={'alpha':1/20});

# Alternative way to plot with the transparency.
# The scatter() function below does NOT have any argument to specify the Jitter
plt.scatter(data = fuel_econ, x = 'year', y = 'comb', alpha=1/20);<jupyter_output><empty_output><jupyter_text>heat map<jupyter_code>plt.figure(figsize=[18,6])

plt.subplot(1,2,1)
sns.regplot(data=fuel_econ, x = 'displ', y='comb', x_jitter=0.04, scatter_kws={'alpha': 1/10}, fit_reg=False)

plt.subplot(1,2,2)
plt.hist2d(data=fuel_econ, x = 'displ', y='comb')
plt.colorbar()
plt.xlabel('Displacement (1)')
plt.ylabel('Combined Fuel Eff. (mpg)');
# Use cmin to set a minimum bound of counts 
# Use cmap to reverse the color map. 
plt.hist2d(data = fuel_econ, x = 'displ', y = 'comb', cmin=0.5, cmap='viridis_r')
plt.colorbar()
plt.xlabel('Displacement (1)')
plt.ylabel('Combined Fuel Eff. (mpg)');
# Specify bin edges 
bins_x = np.arange(0.6, 7+0.3, 0.3)
bins_y = np.arange(12, 58+3, 3)

h2d = plt.hist2d(data = fuel_econ, x = 'displ', y = 'comb', cmin=0.5, cmap='viridis_r', bins = [bins_x, bins_y])
plt.colorbar()
plt.xlabel('Displacement (1)')
plt.ylabel('Combined Fuel Eff. (mpg)');

# Notice the areas of high frequency in the middle of the negative trend in the plot.<jupyter_output><empty_output><jupyter_text>annotation on each cell<jupyter_code># Specify bin edges 
bins_x = np.arange(0.6, 7+0.7, 0.7)
bins_y = np.arange(12, 58+7, 7)
# Use cmin to set a minimum bound of counts 
# Use cmap to reverse the color map. 
h2d = plt.hist2d(data = fuel_econ, x = 'displ', y = 'comb', cmin=0.5, cmap='viridis_r', bins = [bins_x, bins_y])

plt.colorbar()
plt.xlabel('Displacement (1)')
plt.ylabel('Combined Fuel Eff. (mpg)');

# Select the bi-dimensional histogram, a 2D array of samples x and y. 
# Values in x are histogrammed along the first dimension and 
# values in y are histogrammed along the second dimension.
counts = h2d[0]

# Add text annotation on each cell
# Loop through the cell counts and add text annotations for each
for i in range(counts.shape[0]):
    for j in range(counts.shape[1]):
        c = counts[i,j]
        if c >=100: # increase visibility on darker cells
            plt.text(bins_x[i]+0.3, bins_y[j]+3.5, int(c), ha = 'center', va = 'center', color = 'white')
        elif c > 0:
            plt.text(bins_x[i]+0.3, bins_y[j]+3.5, int(c), ha = 'center', va = 'center', color = 'black')

counts.shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15332527206771462, 'fraction_numerical': 0.027569528415961306, 'mean_word_length': 5.228915662650603, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '312317', 'license': 'MIT', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1602, 'n_words': 408, 'path': 'Matplotlib/feng_scatter_correlation.ipynb', 'repo_name': 'feng27/AIPND', 'size': '4135'}