Add line_colours_from_colour_ramp.py
parent
ca2e98aacb
commit
7aea2f0da9
@ -0,0 +1,33 @@
|
|||||||
|
import os
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
# Generate dummy data
|
||||||
|
delta = 0.3
|
||||||
|
x = np.arange(-1.05, 1.1, delta)
|
||||||
|
y = np.arange(-1.05, 1.1, delta)
|
||||||
|
X, Y = np.meshgrid(x, y)
|
||||||
|
Z = X * Y
|
||||||
|
|
||||||
|
# Generate colours from defined colours map
|
||||||
|
cmap = plt.get_cmap('RdYlGn', 10)
|
||||||
|
c = cmap(range(cmap.N))
|
||||||
|
|
||||||
|
# Remove light colours in middle of colour map
|
||||||
|
reds = c[:4, :]
|
||||||
|
greens = c[6:, :]
|
||||||
|
colours = np.vstack([reds, greens])
|
||||||
|
|
||||||
|
fig, ax = plt.subplots(1, 1, figsize=(6, 4))
|
||||||
|
|
||||||
|
for i in range(Z.shape[0]):
|
||||||
|
ax.plot(x, Z[i, :], c=colours[i], linewidth=3, alpha=0.6)
|
||||||
|
|
||||||
|
# Hide spines and ticks
|
||||||
|
ax.set_axis_off()
|
||||||
|
|
||||||
|
# Export figure
|
||||||
|
png_name = os.path.join(
|
||||||
|
'png',
|
||||||
|
os.path.basename(__file__).replace('.py', '.png').replace('_', '-'))
|
||||||
|
plt.savefig(png_name, bbox_inches='tight', dpi=100)
|
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
Loading…
Reference in New Issue