<jupyter_start><jupyter_text>Importing Packages<jupyter_code># Import required packages
%matplotlib inline
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from pylab import cm<jupyter_output><empty_output><jupyter_text>Loading Data<jupyter_code># Use numpy.loadtxt to import our data
wavelength, samp_1_abs, samp_2_abs = np.loadtxt('Absorbance_Data.csv', unpack=True, delimiter=',', skiprows=1)<jupyter_output><empty_output><jupyter_text>Plotting Our Data<jupyter_code># Create figure and add axes object
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])

# Plot and show our data
ax.plot(wavelength, samp_1_abs)
ax.plot(wavelength, samp_2_abs)
plt.show()<jupyter_output><empty_output><jupyter_text>Fonts<jupyter_code>import matplotlib.font_manager as fm

# Collect all the font names available to matplotlib
font_names = [f.name for f in fm.fontManager.ttflist]
print(font_names)<jupyter_output>['STIXSizeFourSym', 'DejaVu Sans Mono', 'cmr10', 'DejaVu Sans Mono', 'DejaVu Serif', 'STIXSizeFiveSym', 'STIXNonUnicode', 'STIXSizeFourSym', 'STIXSizeTwoSym', 'STIXGeneral', 'DejaVu Serif', 'cmmi10', 'DejaVu Sans Mono', 'cmtt10', 'cmex10', 'cmsy10', 'STIXGeneral', 'STIXGeneral', 'DejaVu Sans', 'STIXNonUnicode', 'STIXSizeThreeSym', 'DejaVu Serif', 'STIXSizeThreeSym', 'STIXSizeOneSym', 'STIXNonUnicode', 'STIXGeneral', 'cmss10', 'STIXSizeTwoSym', 'DejaVu Sans', 'DejaVu Sans Mono', 'cmb10', 'STIXSizeOneSym', 'STIXNonUnicode', 'DejaVu Serif', 'DejaVu Sans', 'DejaVu Serif Display', 'DejaVu Sans', 'DejaVu Sans Display', 'Didot', 'Silom', 'Luxi Mono', 'Luxi Mono', 'Raanana', 'Arial Black', '.SF NS Display Condensed', 'Bitstream Vera Serif', 'Hiragino Maru Gothic Pro', 'Chalkboard', 'Kohinoor Telugu', 'Bitstream Vera Sans Mono', 'Ayuthaya', 'Bradley Hand', 'Bitstream Vera Sans Mono', 'Courier New', 'Lao MN', 'System Font', 'Avenir Next Condensed', 'Beirut', '.SF Compact Display', 'Phosphate', '[...]<jupyter_text>General Plot Parameters<jupyter_code># Edit the font, font size, and axes width
mpl.rcParams['font.family'] = 'Avenir'
plt.rcParams['font.size'] = 18
plt.rcParams['axes.linewidth'] = 2<jupyter_output><empty_output><jupyter_text>Generate Set of Colors<jupyter_code># Generate 2 colors from the 'Set1' colormap
colors = cm.get_cmap('tab10', 2)<jupyter_output><empty_output><jupyter_text>Create Figure and Axes<jupyter_code># Create figure object and store it in a variable called 'fig'
fig = plt.figure(figsize=(3, 3))

# Add axes object to our figure that takes up entire figure
ax = fig.add_axes([0, 0, 1, 1])

plt.show()<jupyter_output><empty_output><jupyter_text>Multiple Axis Panels<jupyter_code># Create figure object and store it in a variable called 'fig'
fig = plt.figure(figsize=(3, 3))

# Add two axes objects to create a paneled figure
ax1 = fig.add_axes([0, 0, 1, 0.4])
ax2 = fig.add_axes([0, 0.6, 1, 0.4])

plt.show()<jupyter_output><empty_output><jupyter_text>Axis Insets<jupyter_code># Create figure object and store it in a variable called 'fig'
fig = plt.figure(figsize=(3, 3))

# Add two axes objects to create an inset figure
ax1 = fig.add_axes([0, 0, 1, 1])
ax2 = fig.add_axes([0.5, 0.5, 0.4, 0.4])

plt.show()<jupyter_output><empty_output><jupyter_text>Removing Spines<jupyter_code># Create figure object and store it in a variable called 'fig'
fig = plt.figure(figsize=(3, 3))

# Add axes object to our figure that takes up entire figure
ax = fig.add_axes([0, 0, 1, 1])

# Hide the top and right spines of the axis
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)

plt.show()<jupyter_output><empty_output><jupyter_text>Final Edited Plot  Function to Convert Energy to Wavelength<jupyter_code># Function to convert energy (eV) to wavelength (nm)
def E_to_WL(E):
    return [1240/i for i in E]<jupyter_output><empty_output><jupyter_text>Plotting Script<jupyter_code># Create figure object and store it in a variable called 'fig'
fig = plt.figure(figsize=(3, 3))

# Add axes object to our figure that takes up entire figure
ax = fig.add_axes([0, 0, 1, 1])

# Create new axes object by cloning the y-axis of the first plot
ax2 = ax.twiny()

# Edit the major and minor ticks of the x and y axes
ax.xaxis.set_tick_params(which='major', size=10, width=2, direction='in')
ax.xaxis.set_tick_params(which='minor', size=7, width=2, direction='in')
ax.yaxis.set_tick_params(which='major', size=10, width=2, direction='in', right='on')
ax.yaxis.set_tick_params(which='minor', size=7, width=2, direction='in', right='on')

# Edit the tick parameters of the energy x-axis
ax2.xaxis.set_tick_params(which='major', size=10, width=2, direction='in')
ax2.xaxis.set_tick_params(which='minor', size=7, width=2, direction='in')

# Plot the two sample absorbances, using previously generated colors
ax.plot(wavelength, samp_1_abs, linewidth=2, color=colors(0), label='Sample 1')
ax.plot(wavelength, samp_2_abs, linewidth=2, color=colors(1), label='Sample 2')

# Edit the major and minor tick locations of x and y axes
ax.xaxis.set_major_locator(mpl.ticker.MultipleLocator(100))
ax.xaxis.set_minor_locator(mpl.ticker.MultipleLocator(50))
ax.yaxis.set_major_locator(mpl.ticker.MultipleLocator(0.5))
ax.yaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.25))

# Add ticks manually to energy axis
ax2.xaxis.set_major_locator(mpl.ticker.FixedLocator(E_to_WL(np.linspace(1.5, 3.0, 4))))
ax2.xaxis.set_minor_locator(mpl.ticker.FixedLocator(E_to_WL(np.linspace(1.4, 3.2, 19))))

# Add tick labels manually to energy axis
ax2.set_xticklabels(['1.5', '2.0', '2.5', '3.0'])

# Add the x and y-axis labels
ax.set_xlabel(r'$\mathregular{\lambda}$ (nm)', labelpad=10)
ax.set_ylabel('Absorbance (O.D.)', labelpad=10)

# Add energy axis label
ax2.set_xlabel('Energy (eV)', labelpad=10)

# Set the axis limits
ax.set_xlim(370, 930)
ax.set_ylim(-0.2, 2.2)

# Set the energy axis limits
ax2.set_xlim(370, 930)

# Add legend to plot
ax.legend(bbox_to_anchor=(1, 1), loc=1, frameon=False, fontsize=16)

# Save figure
plt.savefig('Final_Plot.png', dpi=300, transparent=False, bbox_inches='tight')

# Show figure
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14199049024430235, 'fraction_numerical': 0.02852926709296606, 'mean_word_length': 6.731305449936628, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 48, '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': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '389225', 'license': 'MIT', 'n_tokens_mistral': 2445, 'n_tokens_neox': 2292, 'n_words': 590, 'path': 'intro/python-plotting-intro.ipynb', 'repo_name': 'alexlib/python-science-tutorial', 'size': '6099'}