You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
python-snippets/plots/line_colours_from_colour_ma...

34 lines
776 B
Python

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)