Как построить непрерывную тепловую карту точек в 2D - PullRequest
0 голосов
/ 16 апреля 2020

У меня есть такой набор данных:

import numpy as np
x, y = np.meshgrid(np.arange(0, 100, 1), np.arange(0, 100, 1))
loc = np.array([x.flatten(), y.flatten()]).T
vals = np.random.rand(10000).reshape(100, 100)

или с более структурированным распределением:

vals = mvn.pdf(loc,[50, 24], np.array([[ 5 , -2 ], [-2 ,  7]])) + \
       mvn.pdf(loc, [20, 60], np.array([[20, 30], [40, 90]])) + \
       0.4
vals = vals / max(vals)
vals = vals.reshape(100, 100)

Все мои значения находятся в масштабе [0, 1]. Я хочу построить распределение значений в хорошем, непрерывном режиме. Я имею в виду своего рода тепловую карту, которая будет постоянно менять свой цвет в зависимости от значения. Что касается знаю, моя единственная идея - plt.contour - однако, я не удовлетворен результатами.

enter image description here enter image description here

Какие альтернативы у меня есть в matplotlib? Как сделать его «более непрерывным» в случае второго vals?

1 Ответ

0 голосов
/ 16 апреля 2020

Я недавно использовал это для моей программы RAMPIS- C в 2D графике. Если вы хотите его оживить, вам нужно сделать следующее:

import random #I used this for my data

import matplotlib.pyplot as plt   #Used to plot data
from matplotlib.animation import FuncAnimation   #Animation function from matplotlib

x_vals = list()  #Your data my x y preset lists
y_vals = list()

def Animate(I): #Create an animation function
    #Below I create my randomized data over time
    x_vals.append(random.randint(0,5))
    y_vals.append(random.randint(0,5))
    #The following create the graph
    plt.cla() #This clears the graph color such that you don't have issues with randomized colors
    plt.plot(x_vals, y_vals) #This plots the data, use whatever function you want for this

ani = FuncAnimation(plt.gcf(), Animate, interval=100) #The following "Animates" the graph
#Your interval is in ms

plt.tight_layout() #Nicer layout for data, likely not needed in your code
plt.show() #Shows the plot
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...