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

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

如何在每個(gè)點(diǎn)上用文本繪制圖形上的點(diǎn)(python)

如何在每個(gè)點(diǎn)上用文本繪制圖形上的點(diǎn)(python)

精慕HU 2023-04-25 15:25:47
我正在嘗試復(fù)制這個(gè):我有一個(gè)單詞列表,每個(gè)單詞都有一個(gè) x 和 y 坐標(biāo)。我需要像上面那樣繪制它們。做這個(gè)的最好方式是什么?我知道我可以做類似...y = [2.56422, 3.77284, 3.52623, 3.51468, 3.02199]z = [0.15, 0.3, 0.45, 0.6, 0.75]n = [hello, xyz, bbb, fasjd, boy]fig, ax = plt.subplots()for i, txt in enumerate(n):    ax.annotate(txt, (z[i], y[i]))但這對于我想做的事情來說似乎不太有效。對于每個(gè)單詞,我都有一個(gè)函數(shù)來傳遞它以找到 x 坐標(biāo),然后另一個(gè)函數(shù)來找到它的 y 坐標(biāo)。也許只是一個(gè)單詞列表,然后是一個(gè)循環(huán)遍歷并在遍歷列表時(shí)繪制每個(gè)單詞的函數(shù)?這可能嗎?def plotWords(words):    fig, ax = pyplot.subplots()    for w in words:        ax.annotate(w, code for x coordinate, code for y coordinate)    return ax
查看完整描述

2 回答

?
藍(lán)山帝景

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

我想你可以用zip()它們來循環(huán)。


import matplotlib.pyplot as plt


y = [2.56422, 3.77284, 3.52623, 3.51468, 3.02199]

z = [0.15, 0.3, 0.45, 0.6, 0.75]

n = ['hello', 'xyz', 'bbb', 'fasjd', 'boy']


fig = plt.figure(figsize=(4,3),dpi=144)

ax = fig.add_subplot(111)


def plotWords(words,z,y):

    for w,xx,yy in zip(words,z,y):

        ax.annotate(w, xy=(xx,yy))

    ax.set_ylim(0,5)

    plt.show()

    return 


plotWords(n,z,y)

http://img1.sycdn.imooc.com//644780a0000155b805230381.jpg

查看完整回答
反對 回復(fù) 2023-04-25
?
搖曳的薔薇

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

這個(gè)圖

http://img1.sycdn.imooc.com//644780b2000120a706590495.jpg

是運(yùn)行這個(gè)腳本產(chǎn)生的


import matplotlib.pyplot as plt 

import numpy as np 


# determine the sequence of random numbers 

np.random.seed(sum(ord(c) for c in 'gboffi')) 


# initialize the plotting

fig, ax = plt.subplots(figsize=(8,6), constrained_layout=1) 


# a list of long words 

N = 40 

data = '/usr/share/dict/italian' 

long_words = [w.strip() for w in open(data) if len(w)>12 and "'" not in w] 

words = np.random.choice(long_words, N) 


# let's compute the word characteristics

xs = np.random.random(N) + [len(w) for w in words] 

ys = np.random.random(N) + [sum(ord(c) for c in w)/len(w) for w in words] 

# determine the axes limits

xmn = min(xs) ; xmx = max(xs) ; dx = xmx-xmn 

ymn = min(ys) ; ymx = max(ys) ; dy = ymx-ymn 

ax.set_xlim(xmn-0.05*dx, xmx+0.05*dx) ; ax.set_ylim(ymn-0.05*dy, ymx+0.05*dx) 

# label the axes

plt.xlabel('Word Length', size='x-large')

plt.ylabel('Mean Value', size='x-large')


# for every word, plot a red "o" and place the text around it 

for w, x, y in zip(words, xs, ys): 

    ax.plot((x,),(y,), 'o', c='r') 

    ax.annotate(w, (x, y), ha='center', va='center')


# the dashed red lines, the position is a little arbitrary

plt.hlines(ymn+0.5*dy, xmn, xmx, ls='--', color='r') 

plt.vlines(xmn+0.4*dx, ymn, ymx, ls='--', color='r')                                                                


# remove everything except points, red lines and axes' labels

plt.box(False)

plt.tick_params(left=0, top=0, right=0, bottom=0,

                labelleft=0, labeltop=0, labelright=0, labelbottom=0) 

# we are done

plt.show()


查看完整回答
反對 回復(fù) 2023-04-25
  • 2 回答
  • 0 關(guān)注
  • 101 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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