<jupyter_start><jupyter_text>PYT-DS: More Plotting in MatplotlibLets keep revealing the mysteries of plotting with matplotlib. I'm still following VanderPlas closely as I think his materials are top notch.  They're also freely available as open source products.  Avail yourselves!  Take advantage of what has been accomplished to make your lives easier!Links:    * [HTML](https://jakevdp.github.io/PythonDataScienceHandbook/index.html)       * [The Notebooks](https://github.com/jakevdp/PythonDataScienceHandbook/tree/master/notebooks)<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('seaborn-white') # didn't have to import seaborn
import numpy as np
fig, ax_array = plt.subplots(2, 3, sharex='col', sharey='row') # ta da!<jupyter_output><empty_output><jupyter_text>The axes show up in an array this time.  We cycle through them...<jupyter_code># axes are in a two-dimensional array, indexed by [row, col]
for i in range(2):
    for j in range(3):
        ax_array[i, j].text(0.5, 0.5, str((i, j)),
                      fontsize=18, ha='center')
fig
grid = plt.GridSpec(2, 3, wspace=0.4, hspace=0.3)
plt.subplot(grid[0, 0])
plt.subplot(grid[0, 1:])
plt.subplot(grid[1, :2])
plt.subplot(grid[1, 2]);<jupyter_output><empty_output><jupyter_text>There's lots going on in this VanderPlas plot below, a practical application of Gridspec.  Gridspec gets the ball rollowing, at which point we create three subplots and name the axes.Notice the shared axes.numpy does the heavy lifting, in terms of providing 3000 points with a given mean and covariance.  You might want to play around with these settings.  Indeed, lets turn that into a.... LAB:What does the cov argument do?  Try making some other changes, in terms of colors, marker size, transparency...  Get familiar with the bells and whistles, starting with something that already works!<jupyter_code># Create some normally distributed data
mean = [0, 0]
cov = [[1, 1], [1, 2]]
x, y = np.random.multivariate_normal(mean, cov, 3000).T

# Set up the axes with gridspec
fig = plt.figure(figsize=(6, 6))
grid = plt.GridSpec(4, 4, hspace=0.2, wspace=0.2)
main_ax = fig.add_subplot(grid[:-1, 1:])
y_hist = fig.add_subplot(grid[:-1, 0], xticklabels=[], sharey=main_ax)
x_hist = fig.add_subplot(grid[-1, 1:], yticklabels=[], sharex=main_ax)

# scatter points on the main axes
main_ax.plot(x, y, 'ok', markersize=3, alpha=0.2)

# histogram on the attached axes
x_hist.hist(x, 40, histtype='stepfilled',
            orientation='vertical', color='gray')
x_hist.invert_yaxis()

y_hist.hist(y, 40, histtype='stepfilled',
            orientation='horizontal', color='gray')
y_hist.invert_xaxis()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12072808320950966, 'fraction_numerical': 0.021916790490341752, 'mean_word_length': 4.867102396514161, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '464920', 'license': 'MIT', 'n_tokens_mistral': 961, 'n_tokens_neox': 894, 'n_words': 292, 'path': 'PLOTTING_PYT_DS_SAISOFT.ipynb', 'repo_name': '4dsolutions/Python5', 'size': '2692'}