# How to plot a 2D array as in Python?

**URL:** https://discourse.julialang.org/t/how-to-plot-a-2d-array-as-in-python/74324
**Category:** New to Julia
**Tags:** question, plotting, python
**Created:** [January 10, 2022, 10:41am UTC](https://discourse.julialang.org/t/how-to-plot-a-2d-array-as-in-python/74324 "2022-01-10T10:41:50Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Shivam\_Jha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shivam_jha/32/32303_2.png) [@Shivam\_Jha](https://discourse.julialang.org/u/Shivam_Jha)
#### Post date: [January 10, 2022, 10:41am UTC](https://discourse.julialang.org/t/how-to-plot-a-2d-array-as-in-python/74324/1 "2022-01-10T10:41:50Z")

</div>

```julia
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](https://global.discourse-cdn.com/julialang/original/3X/3/b/3b7a3ce28854350743c71ce87d77268382cd0f81.png)

---

<div class="post-metadata">

### Author: ![Bernard\_GODARD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernard_godard/32/4155_2.png) [@Bernard\_GODARD](https://discourse.julialang.org/u/Bernard_GODARD)
#### Post date: [January 10, 2022, 11:55am UTC](https://discourse.julialang.org/t/how-to-plot-a-2d-array-as-in-python/74324/2 "2022-01-10T11:55:27Z")

</div>

```julia
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(ρ)

```

---

<div class="post-metadata">

### Author: ![erny123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erny123/32/52255_2.png) [@erny123](https://discourse.julialang.org/u/erny123)
#### Post date: [November 8, 2023, 12:26am UTC](https://discourse.julialang.org/t/how-to-plot-a-2d-array-as-in-python/74324/3 "2023-11-08T00:26:27Z")

</div>

heatmap() is incredibly slow for large data sets in Julia.  
there should be a possibility of using python’s `imshow()` but I have no idea how to change the color map and aspect ratio using actual pythonplots
