<jupyter_start><jupyter_text>Primary Approach<jupyter_code>x = np.arange(0,8*np.pi,0.1)
y1 = np.sin(x)
y2 = np.exp(x)
fig, ax = plt.subplots()
ax.plot(x,y1)
ax.set_title('sin(x)')

plt.show()
fig, ax = plt.subplots()
ax.plot(x,y2)
ax.set_title('exp(x)')

plt.show()
fig, ax = plt.subplots()
ax.plot(x,y1)
ax.plot(x,y2)
ax.set_title('sin(x) and exp(x)')
ax.legend(['sin(x)','exp(x)'])

plt.show()
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(12,4))

ax1.plot(x,y1)
ax1.set_title('sin(x)')

ax2.plot(x,y2,'C1')
ax2.set_title('exp(x)')

plt.show()
fig, ax1 = plt.subplots()

ax1.plot(x,y1)
ax1.set_title('sin(x) and exp(x)')

ax2 = ax1.twinx()
ax2.plot(x,y2,'C1')

plt.show()
fig, ax1 = plt.subplots()

ax1.plot(x,y1)
ax1.set_ylabel('sin(x)', color='C0')
ax1.tick_params(axis='y', color='C0', labelcolor='C0')

ax1.set_title('sin(x) and exp(x)')

ax2 = ax1.twinx()
ax2.plot(x,y2,'C1')
ax2.set_ylabel('exp(x)', color='C1')
ax2.tick_params(axis='y', color='C1', labelcolor='C1')
ax2.spines['right'].set_color('C1')
ax2.spines['left'].set_color('C0')

plt.show()
fig, ax1 = plt.subplots()

ax1.plot(x,y1)
ax1.set_ylabel('sin(x)', color='C0')
ax1.tick_params(axis='y', color='C0', labelcolor='C0')

ax1.set_title('sin(x) and exp(x)')

ax2 = ax1.twinx()
ax2.plot(x,y2,'C1')
ax2.set_ylabel('exp(x)', color='C1')
ax2.tick_params(axis='y', color='C1', labelcolor='C1')
ax2.spines['right'].set_color('C1')
ax2.spines['left'].set_color('C0')

fig.legend(['sin(x)','exp(x)'], bbox_to_anchor=(0.9, 0.8))

plt.show()<jupyter_output><empty_output><jupyter_text>Alternative way to add a legend to a y-y plot<jupyter_code>fig, ax1 = plt.subplots()

line1 = ax1.plot(x,y1)
ax1.set_ylabel('sin(x)', color='C0')
ax1.tick_params(axis='y', color='C0', labelcolor='C0')

ax1.set_title('sin(x) and exp(x)')

ax2 = ax1.twinx()
line2 = ax2.plot(x,y2,'C1')
ax2.set_ylabel('exp(x)', color='C1')
ax2.tick_params(axis='y', color='C1', labelcolor='C1')
ax2.spines['right'].set_color('C1')
ax2.spines['left'].set_color('C0')

lines = line1 + line2
ax2.legend(lines, ['sin(x)','exp(x)'])

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2539155196962506, 'fraction_numerical': 0.05268153773137162, 'mean_word_length': 7.170542635658915, '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': '232454', 'license': 'MIT', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1061, 'n_words': 138, 'path': 'y-y plots with Matplotlib.ipynb', 'repo_name': 'rhazra-003/Ploting_Practice', 'size': '2107'}