简体   繁体   中英

Transition line in heat map - python

I have problem that I can't seem to work around. I have a grid of values that I have interpolated using scipys griddata. The values have been visualized as a heat map with values in [0,1]. Now I would like to plot a transition line for values 1/2.

Is this possible? My first idea was to extract the coordinates from grid_z that corresponds to 1/2 and using the coordinates for a line plot, but I'm not sure how to do that.

Thank you in advance.

EDIT: Solved it via

xInd, yInd = np.where(np.logical_and(grid_z.T > 0.49, grid_z.T < 0.51))

and then plotting the line!

You can use contour() for that:

import numpy
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

x = numpy.linspace(0, 2*numpy.pi, 200)
y = numpy.linspace(0, 2*numpy.pi, 200)

xx, yy = numpy.meshgrid(x, y)

z = numpy.sin(xx) * numpy.cos(yy)

fig = plt.figure()
s = fig.add_subplot(1, 1, 1)
s.imshow(z, vmin=0, vmax=1)
s.contour(z, levels=[0.5])
fig.savefig('t.png')

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM