Add discrete_colour_ramp.py
parent
e663f9ea97
commit
0fe64dc43b
@ -0,0 +1,5 @@
|
||||
# plots
|
||||
|
||||
## discrete_colour_ramp.py
|
||||
|
||||
![discrete colour ramp](png/discrete-colour-ramp.png)
|
@ -0,0 +1,39 @@
|
||||
import os
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Generate dummy data
|
||||
delta = 0.01
|
||||
x = np.arange(-3.0, 3.0, delta)
|
||||
y = np.arange(-3.0, 3.0, delta)
|
||||
X, Y = np.meshgrid(x, y)
|
||||
Z = X * Y
|
||||
|
||||
# Set range and steps for colour bar
|
||||
c_max = 8
|
||||
c_min = -8
|
||||
c_step = 2
|
||||
|
||||
# Create colour map
|
||||
cmap = plt.cm.get_cmap('Blues', (c_max - c_min + c_step) / c_step)
|
||||
|
||||
fig, ax = plt.subplots(1, 1, figsize=(6, 4))
|
||||
|
||||
# Plot image
|
||||
im = ax.imshow(Z,
|
||||
cmap=cmap,
|
||||
interpolation='bilinear',
|
||||
vmax=c_max + c_step / 2,
|
||||
vmin=c_min - c_step / 2)
|
||||
|
||||
# Add colour bar
|
||||
plt.colorbar(im, ticks=np.arange(c_min, c_max + 1, c_step))
|
||||
|
||||
# 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: 7.5 KiB |
Loading…
Reference in New Issue