第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

沒(méi)有使用 Matplotlib Python 在后臺(tái)獲取熱圖

沒(méi)有使用 Matplotlib Python 在后臺(tái)獲取熱圖

炎炎設(shè)計(jì) 2021-11-16 16:07:06
我試過(guò)這個(gè)并得到如圖所示的結(jié)果:import pandas as pdimport matplotlib.pyplot as pltimport numpy as npfrom matplotlib.colors import LinearSegmentedColormapcmap = LinearSegmentedColormap.from_list("", ["red","grey","green"])df = pd.read_csv('t.csv', header=0)fig = plt.figure()ax1 = fig.add_subplot(111)ax = ax1.twiny()# Scatter plot of positive points, coloured blue (C0)ax.scatter(np.argwhere(df['real'] > 0), df.loc[df['real'] > 0, 'real'], color='C2')# Scatter plot of negative points, coloured red (C3)ax.scatter(np.argwhere(df['real'] < 0), df.loc[df['real'] < 0, 'real'], color='C3')# Scatter neutral values in grey (C7)ax.scatter(np.argwhere(df['real'] == 0), df.loc[df['real'] == 0, 'real'], color='C7')ax.set_ylim([df['real'].min(), df['real'].max()])index = len(df.index)ymin = df['prediction'].min()ymax= df['prediction'].max()ax1.imshow([np.arange(index),df['prediction']],cmap=cmap,                        extent=(0,index-1,ymin, ymax), alpha=0.8)plt.show()圖片:我期待一個(gè)輸出,其中根據(jù)圖放置顏色。我得到綠色,沒(méi)有紅色或灰色。我想讓圖像或輪廓按值傳播。我怎么能做到這一點(diǎn)?見(jiàn)下圖,類(lèi)似的東西:請(qǐng)讓我知道我如何實(shí)現(xiàn)這一目標(biāo)。我使用的數(shù)據(jù)在這里:t.csv對(duì)于實(shí)時(shí)版本,請(qǐng)查看Tensorflow Playground
查看完整描述

2 回答

?
德瑪西亞99

TA貢獻(xiàn)1770條經(jīng)驗(yàn) 獲得超3個(gè)贊

像這樣的解決方案基本上需要 2 個(gè)任務(wù):

  • 繪制熱圖作為背景;

  • 繪制散點(diǎn)數(shù)據(jù);

輸出

http://img1.sycdn.imooc.com//619366df000159fd06200671.jpg

源代碼:


import numpy as np

import matplotlib.pyplot as plt


###

# Plot heatmap in the background

###


# Setting up input values

x = np.arange(-6.0, 6.0, 0.1)

y = np.arange(-6.0, 6.0, 0.1)

X, Y = np.meshgrid(x, y)


# plot heatmap colorspace in the background

fig, ax = plt.subplots(nrows=1)

im = ax.imshow(X, cmap=plt.cm.get_cmap('RdBu'), extent=(-6, 6, -6, 6), interpolation='bilinear')

cax = fig.add_axes([0.21, 0.95, 0.6, 0.03]) # [left, bottom, width, height]

fig.colorbar(im, cax=cax, orientation='horizontal')  # add colorbar at the top


###

# Plot data as scatter

###

# generate the points

num_samples = 150

theta = np.linspace(0, 2 * np.pi, num_samples)


# generate inner points

circle_r = 2

r = circle_r * np.random.rand(num_samples)

inner_x, inner_y = r * np.cos(theta), r * np.sin(theta)


# generate outter points

circle_r = 4

r = circle_r + np.random.rand(num_samples)

outter_x, outter_y = r * np.cos(theta), r * np.sin(theta)


# plot data

ax.scatter(inner_x, inner_y, s=30, marker='o', color='royalblue', edgecolors='white', linewidths=0.8)

ax.scatter(outter_x, outter_y, s=30, marker='o', color='crimson', edgecolors='white', linewidths=0.8)

ax.set_ylim([-6,6])

ax.set_xlim([-6,6])


plt.show()

為了簡(jiǎn)單起見(jiàn),我保留了顏色條范圍(-6, 6)以匹配數(shù)據(jù)范圍。


我確信可以更改此代碼以滿(mǎn)足您的特定需求。祝你好運(yùn)!


查看完整回答
反對(duì) 回復(fù) 2021-11-16
?
阿晨1998

TA貢獻(xiàn)2037條經(jīng)驗(yàn) 獲得超6個(gè)贊

這是一個(gè)可能的解決方案。

一些注意事項(xiàng)和問(wèn)題:

  • 您的數(shù)據(jù)文件中的“預(yù)測(cè)”值是多少?它們似乎與“真實(shí)”列中的值無(wú)關(guān)。

  • 為什么要?jiǎng)?chuàng)建第二個(gè)軸?圖中底部 X 軸代表什么?我刪除了第二個(gè)軸并標(biāo)記了剩余的軸(索引和實(shí)數(shù))。

  • 當(dāng)您對(duì) Pandas DataFrame 進(jìn)行切片時(shí),索引會(huì)隨之而來(lái)。您不需要?jiǎng)?chuàng)建單獨(dú)的索引(代碼中的 argwhere 和 arange(index))。我簡(jiǎn)化了代碼的第一部分,其中生成了散點(diǎn)圖。

import pandas as pd

import matplotlib.pyplot as plt

import numpy as np

from matplotlib.colors import LinearSegmentedColormap

cmap = LinearSegmentedColormap.from_list("", ["red","grey","green"])

df = pd.read_csv('t.csv', header=0)

print(df)


fig = plt.figure()

ax = fig.add_subplot(111)


# Data limits

xmin = 0

xmax = df.shape[0]

ymin = df['real'].min()

ymax = df['real'].max()


# Scatter plots

gt0 = df.loc[df['real'] > 0, 'real']

lt0 = df.loc[df['real'] < 0, 'real']

eq0 = df.loc[df['real'] == 0, 'real']

ax.scatter(gt0.index, gt0.values, edgecolor='white', color='C2')

ax.scatter(lt0.index, lt0.values, edgecolor='white', color='C3')

ax.scatter(eq0.index, eq0.values, edgecolor='white', color='C7')

ax.set_ylim((ymin, ymax))

ax.set_xlabel('index')

ax.set_ylabel('real')


# We want 0 to be in the middle of the colourbar, 

# because gray is defined as df['real'] == 0

if abs(ymax) > abs(ymin):

    lim = abs(ymax)

else:

    lim = abs(ymin)


# Create a gradient that runs from -lim to lim in N number of steps,

# where N is the number of colour steps in the cmap.

grad = np.arange(-lim, lim, 2*lim/cmap.N)


# Arrays plotted with imshow must be 2D arrays. In this case it will be

# 1 pixel wide and N pixels tall. Set the aspect ratio to auto so that

# each pixel is stretched out to the full width of the frame.

grad = np.expand_dims(grad, axis=1)

im = ax.imshow(grad, cmap=cmap, aspect='auto', alpha=1, origin='bottom',

               extent=(xmin, xmax, -lim, lim))

fig.colorbar(im, label='real')

plt.show()

這給出了以下結(jié)果:

http://img1.sycdn.imooc.com//619366fb00010bb916171102.jpg

查看完整回答
反對(duì) 回復(fù) 2021-11-16
  • 2 回答
  • 0 關(guān)注
  • 262 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)