How to plot a 2D array as in Python?

import matplotlib.pyplot as plt
import numpy as np  
N                      = 64 # resolution N x 3N
boxsizeX               = 0.5
boxsizeY               = 1.5
dx = boxsizeX / N
vol = dx**2
xlin = np.linspace(0.5*dx, boxsizeX-0.5*dx, N)
ylin = np.linspace(0.5*dx, boxsizeY-0.5*dx, 3*N)
Y, X = np.meshgrid( ylin, xlin )

rho = 1. + (Y > 0.75)

fig = plt.figure(figsize=(4,4), dpi=80)
plt.cla()
plt.imshow(rho.T)

image

using Plots
N                      = 64 # resolution N x 3N
boxsizeX               = 0.5
boxsizeY               = 1.5
dx = boxsizeX / N
vol = dx^2
xlin = range(0.5*dx, boxsizeX-0.5*dx,length=N)
ylin = range(0.5*dx, boxsizeY-0.5*dx, length=3*N)
ρ=(0*xlin').+(ylin.>0.75).+1
heatmap(ρ)
1 Like