python带标签的坐标系_得到正确的坐标轴标签中imshow在python

from pylab import meshgrid,cm,imshow,contour,clabel,colorbar,axis,title,show

import numpy as np

from numpy import exp,arange

import matplotlib.pyplot as plt

def z_func(x,y):

func = 3.0*(1.0 - x)**2*np.exp(-x**2 - (y+1.0)**2) - 10.0*(x/5.0 - x**3 - y**5)*np.exp(-x**2 - y**2) - 0.33*np.exp(-(x + 1.0)**2 - y**2)

return func

x = arange(-4.0,4.0,0.1)

y = arange(-4.0,4.0,0.1)

X,Y = meshgrid(x, y) # grid of point

Z = z_func(X, Y)

fig = plt.figure(figsize=(10,6))

im = imshow(Z,cmap=cm.RdBu) # drawing the function

# adding the Contour lines with labels

cset = contour(Z,arange(-1,1.5,0.2),linewidths=2,cmap=cm.Set2)

clabel(cset,inline=True,fmt='%1.1f',fontsize=10)

colorbar(im) # adding the colobar on the right

# latex fashion title

title('peaks function')

show()

我偷了从somehwere上StackExchange。我很难得到x和y轴来显示正确的域,[-4,4]。已经发布了许多不适合我的解决方案,例如Change values on matplotlib imshow() graph axis和correcting the axes using imshow,但它们都没有保持图像的方式并重新映射轴。帮帮我!!!

+0

此代码无法使用。你只是想为imshow设置轴限制吗? –

+0

该代码适用于我。我忘了我的进口...让我现在进入。我想要轴反映我的输入变量的实际范围,[-4,4] –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值