Code snippets for matplotlib
¶
- todo: try formatting this with Quarto
- todo: show single color
- todo: show color pallete
- todo: reverse color pallete
In [1]:
Copied!
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
In [2]:
Copied!
fig, ax = plt.subplots(figsize=(7,7))
x = np.linspace(0, 1, 1000)
y = x**.4
ax.plot(x, y, '-C0', alpha=.7, label='smooth')
ax.plot(x, x, '--', alpha=.3, color='red')
x = np.linspace(0, 1, 10)
y = x**.4
ax.plot(x, y, '-oC1', alpha=.7, label='dotty')
ax.vlines(x, 0, 1, alpha=.3)
ax.hlines(y, 0, 1, alpha=.3)
ax.grid(False)
ax.set_aspect('equal')
ax.legend(loc='lower right', framealpha=1.0)
ax.set(
xlabel = 'stuff down here',
ylabel = 'stuff over here',
title = 'axis title',
)
fig.suptitle('the suptitle', fontsize=16)
fig.tight_layout()
# fig.savefig('test.png', dpi=200, facecolor='white')
fig, ax = plt.subplots(figsize=(7,7))
x = np.linspace(0, 1, 1000)
y = x**.4
ax.plot(x, y, '-C0', alpha=.7, label='smooth')
ax.plot(x, x, '--', alpha=.3, color='red')
x = np.linspace(0, 1, 10)
y = x**.4
ax.plot(x, y, '-oC1', alpha=.7, label='dotty')
ax.vlines(x, 0, 1, alpha=.3)
ax.hlines(y, 0, 1, alpha=.3)
ax.grid(False)
ax.set_aspect('equal')
ax.legend(loc='lower right', framealpha=1.0)
ax.set(
xlabel = 'stuff down here',
ylabel = 'stuff over here',
title = 'axis title',
)
fig.suptitle('the suptitle', fontsize=16)
fig.tight_layout()
# fig.savefig('test.png', dpi=200, facecolor='white')
In [ ]:
Copied!
Last update:
October 31, 2022