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

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

Pyplot:以自定義比例繪制圖形(x 和 y)

Pyplot:以自定義比例繪制圖形(x 和 y)

catspeake 2023-03-22 10:50:01
我一直在 Jupyter Notebook 中使用以下代碼繪制數(shù)據(jù)框:為了與僅在紙上以 0.005mm=1cm 比例提供的舊數(shù)據(jù)進(jìn)行比較,我需要以相同比例導(dǎo)出和打印圖形:0.005mm in the圖(x 軸和 y 軸)在圖中必須為 1cm。有什么辦法可以定義自定義比例嗎?有關(guān)信息,x 范圍和 y 范圍不是固定的,它們會(huì)根據(jù)我加載到數(shù)據(jù)框中的數(shù)據(jù)而有所不同。import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport seaborn as sns            import matplotlib.ticker as tickerdf = pd.DataFrame(np.array([[1.7, 0], [1.75, -0.012], [1.8, 0]]),                   columns=['pos', 'val'])                  # Plot resultssns.set()plt.figure(figsize=(20,30))plt.plot(df['pos'], df['val'])ax = plt.axes()ax.set_aspect('equal')plt.xlabel('Position [mm]')plt.ylabel('H?he [mm]')ax.xaxis.set_major_locator(ticker.MultipleLocator(0.005))ax.yaxis.set_major_locator(ticker.MultipleLocator(0.005))plt.show()
查看完整描述

2 回答

?
開滿天機(jī)

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


http://img4.sycdn.imooc.com/641a6d060001aede06440259.jpg

import matplotlib.pyplot as plt


from mpl_toolkits.axes_grid1 import Divider, Size

from mpl_toolkits.axes_grid1.mpl_axes import Axes


cm = lambda d: d/2.54


x, y = [1700.0, 1725.0, 1750.0], [0.0, -12.0, 0.0] # μm

dx, dy = 50.0, 12.0


# take margins into account

xmin, xmax = min(x)-dx*0.05, max(x)+dx*0.05

ymin, ymax = min(y)-dy*0.05, max(y)+dy*0.05

dx, dy = xmax-xmin, ymax-ymin


# 5 μm data == 1 cm plot

scale = 5/1

xlen, ylen = dx/scale, dy/scale


# Now we know the extents of our data and the axes dimension,

# so we can set the Figure dimensions, taking borders into account

left, right = 2, 1

bot, top = 1.5, 1.5

fig = plt.figure(

? ? figsize=(cm(left+xlen+right), cm(bot+ylen+top)),

? ? dpi=118)


# change bg color to show so that one can measure the figure

# and the axes when pasted into SO and do their math…

fig.set_facecolor('xkcd:grey teal')


##########? Below is stolen from Matplotlib Fixed Size Axes

########## (please don't ask me…)

# Origin and size of the x axis and y axis

h = [Size.Fixed(cm(left)), Size.Fixed(cm(xlen))]

v = [Size.Fixed(cm(bot)), Size.Fixed(cm(ylen))]

divider = Divider(fig, (0.0, 0.0, 1., 1.), h, v, aspect=False)

# NB: Axes is from mpl_toolkits.axes_grid1.mpl_axes

ax = Axes(fig, divider.get_position())

ax.set_axes_locator(divider.new_locator(nx=1, ny=1))

fig.add_axes(ax)

#########? Above is stolen from Matplotlib Fixed Size Axes Demo?


plt.plot(x,y)

plt.grid()

ax.set(xlim=(xmin, xmax), ylim=(ymin, ymax), yticks=range(-12,1,3),

? ? ? ?xlabel='X/μm', ylabel='Y/μm',

? ? ? ?title='X vs Y, 1 cm on plot equals 5 μm')

fig.suptitle('Figure dimensions: w = %.2f cm, h = %.2f cm.'%(

? ? left+xlen+right, bot+ylen+top))


fig.savefig('Figure_1.png',

? ? ? ? ? ? # https://stackoverflow.com/a/4805178/2749397, Joe Kington's

? ? ? ? ? ? facecolor=fig.get_facecolor(), edgecolor='none')


查看完整回答
反對(duì) 回復(fù) 2023-03-22
?
繁星點(diǎn)點(diǎn)滴滴

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

1 英寸 = 2.54 厘米,所以 254/0.005 = 50800 dpi

plt.figure(figsize=(20,30), dpi=50800)


查看完整回答
反對(duì) 回復(fù) 2023-03-22
  • 2 回答
  • 0 關(guān)注
  • 227 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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