<jupyter_start><jupyter_text>Plotting with matplotlib<jupyter_code># most common way to import matplotlib
from matplotlib import pyplot as plt
# import numpy to work with data to plot
import numpy as np
# Magic Command that sets how matplotlib integrates into the ipython notebook. 
%matplotlib inline
# Setup for darkmode browser
plt.style.use('dark_background')
x = np.linspace(-2,2, 50)
y = np.cos(x)
plt.figure(figsize=(7,5))
plt.plot(x,y, ".-")
plt.xlabel("time (s)")
plt.ylabel("Voltage (V)")<jupyter_output><empty_output><jupyter_text>What is matplotlib? - Matplotlib is basically Matlabs plotting translated into Python. (Similar to numpy which is also heavily based on Matlab.)|  - It's cumbersome but versatile - It can make paper quality plots but is maybe not the right choice for live plotting.  How to best use Matplotlib- create a style file - import that file in different scripts and notebooks for consistency- if you want to do things quickly  - use subplot and tight_layout- if you want to create polished paper figures  - use gridspec for multi-axis plots   - use subplots_adjust to manage whitespace around figure<jupyter_code># Do not run %matplotlib inline after these definitions, else they will get overwritten
import matplotlib

fnt_size = 13.
full_fig_width = 12.2
full_fig_width_in = full_fig_width/2.54


my_font = {'sans-serif':'Arial'}
my_font.update({'size':fnt_size})
matplotlib.rc('font', **my_font)

my_axes = {'formatter.useoffset':False,
			'labelsize':fnt_size,
			'titlesize':fnt_size}
matplotlib.rc('axes',**my_axes)

# my_xtick = {'major.pad':8,
#             'minor.pad':8}
my_xtick = {'direction':'in',
			'top':True}
matplotlib.rc('xtick',**my_xtick)
my_ytick = {'direction':'in',
			'right':True}
matplotlib.rc('ytick',**my_ytick)
              
# ax.ticklabel_format(useOffset=False)

# figure = {'subplot.bottom': 0.1,
#           'subplot.left': 0.15}
# figure.subplot.hspace: 0.2
# figure.subplot.left: 0.125
# figure.subplot.right: 0.9
# figure.subplot.top: 0.9
# figure.subplot.wspace: 0.2}
# matplotlib.rc('figure',**figure)

# legend = {'frameon':False,
#          'fontsize':'small'}
legend = {'numpoints':1,
		'handlelength':1,
			'frameon':'False',
         'fontsize':fnt_size,
          'loc':'best'}
matplotlib.rc('legend', **legend)


my_line = {'linewidth':0.75,
			'markersize':3}
matplotlib.rc('lines', **my_line)
x = np.linspace(-2,2, 50)
y = np.cos(x)
plt.figure(figsize=(7,5))
plt.plot(x,y, ".-")
plt.xlabel("time (s)")
plt.ylabel("Voltage (V)")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14403778040141677, 'fraction_numerical': 0.01770956316410862, 'mean_word_length': 4.699551569506727, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '501671', 'license': 'MIT', 'n_tokens_mistral': 975, 'n_tokens_neox': 905, 'n_words': 232, 'path': 'Plotting with matplotlib.ipynb', 'repo_name': 'cdickel/ML4Q_retreat_python_workshop', 'size': '2541'}