小编Sam*_*Sam的帖子

Matplotlib:ValueError:x和y必须具有相同的第一个维度

我试图在我的matplotlib图中拟合最适合的线性线.我不断得到x和y没有相同的第一个维度的错误.但他们都有15个长度.我做错了什么?

import matplotlib.pyplot as plt
from scipy import stats
import numpy as np

x = [0.46,0.59,0.68,0.99,0.39,0.31,1.09,0.77,0.72,0.49,0.55,0.62,0.58,0.88,0.78]
y = [0.315,0.383,0.452,0.650,0.279,0.215,0.727,0.512,0.478,0.335,0.365,0.424,0.390,0.585,0.511]
xerr = [0.01]*15
yerr = [0.001]*15

plt.rc('font', family='serif', size=13)
m, b = np.polyfit(x, y, 1)
plt.plot(x,y,'s',color='#0066FF')
plt.plot(x, m*x + b, 'r-') #BREAKS ON THIS LINE
plt.errorbar(x,y,xerr=xerr,yerr=0,linestyle="None",color='black')
plt.xlabel('$\Delta t$ $(s)$',fontsize=20)
plt.ylabel('$\Delta p$ $(hPa)$',fontsize=20)
plt.autoscale(enable=True, axis=u'both', tight=False)
plt.grid(False)
plt.xlim(0.2,1.2)
plt.ylim(0,0.8)
plt.show()
Run Code Online (Sandbox Code Playgroud)

python numpy matplotlib

33
推荐指数
2
解决办法
15万
查看次数

Python将椭圆拟合到图像

我有一个使用OpenCV的网络摄像头,我正在尝试实时拟合椭圆.

我目前使用的代码可以工作,但很多时候它无法在图像中使用椭圆.我还可以采用哪种椭圆拟合图像的方法?

当前代码:

def find_ellipses(img): #img is grayscale image of what I want to fit
        ret,thresh = cv2.threshold(img,127,255,0)
        _,contours,hierarchy = cv2.findContours(thresh, 1, 2)

        if len(contours) != 0:
            for cont in contours:
                if len(cont) < 5:
                    break
                elps = cv2.fitEllipse(cont)
                return elps  #only returns one ellipse for now
        return None
Run Code Online (Sandbox Code Playgroud)

elps形式在哪里(x_centre,y_centre),(minor_axis,major_axis),angle

以下是我想成功拟合椭圆的示例.当我不想要它时,我当前的代码会失败.

在此输入图像描述

python opencv ellipse

12
推荐指数
1
解决办法
5007
查看次数

如何使用matplotlib绘制元组列表?

我有一个元组是(元组的列表minTemp,averageTemp,maxTemp).我想在同一个matplotlib图上绘制元组中每个元素的折线图.

如何才能做到这一点?

python tuples list matplotlib

5
推荐指数
1
解决办法
1万
查看次数

霍夫圆转换为圆形阴影

我有一个图像,我试图将Hough圆形变换应用于视图中的圆形对象.

我很难找到一个适合气缸外部阴影的圆圈.可以做些什么来正确地分割这个阴影并轻松地适应它的圆圈?

码:

img = cv2.medianBlur(im,7)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)

plt.imshow(cimg)
plt.show()

circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,20,
                            param1=50,param2=150,minRadius=100,maxRadius=0)

circles = np.uint16(np.around(circles))

for i in circles[0,:]:
    # draw the outer circle
    cv2.circle(cimg,(i[0],i[1]),i[2],(255,0,0),10)
    # draw the center of the circle
    cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),20)

    radius = i[2]
    print 'radius', radius, 'px'

plt.imshow(cimg)
plt.show()
Run Code Online (Sandbox Code Playgroud)

python geometry opencv hough-transform

5
推荐指数
1
解决办法
375
查看次数

Tkinter显示启动画面并隐藏主屏幕,直到__init__完成

我有一个主tkinter窗口,可能需要几秒钟才能正确加载.因此,我希望有一个启动画面,直到主类的init方法完成,并且可以显示主tkinter应用程序.怎么能实现这一目标?

启动画面代码:

from Tkinter import *
from PIL import Image, ImageTk
import ttk

class DemoSplashScreen: 
    def __init__(self, parent): 
        self.parent = parent 
        self.aturSplash() 
        self.aturWindow() 

    def aturSplash(self): 
        self.gambar = Image.open('../output5.png')
        self.imgSplash = ImageTk.PhotoImage(self.gambar)

    def aturWindow(self):
        lebar, tinggi = self.gambar.size 
        setengahLebar = (self.parent.winfo_screenwidth()-lebar)//2 
        setengahTinggi = (self.parent.winfo_screenheight()-tinggi)//2
        self.parent.geometry("%ix%i+%i+%i" %(lebar, tinggi, setengahLebar,setengahTinggi))
        Label(self.parent, image=self.imgSplash).pack()


if __name__ == '__main__': 
    root = Tk()
    root.overrideredirect(True) 
    progressbar = ttk.Progressbar(orient=HORIZONTAL, length=10000, mode='determinate') 
    progressbar.pack(side="bottom") 
    app = DemoSplashScreen(root) 
    progressbar.start()
    root.after(6010, root.destroy) 
    root.mainloop()
Run Code Online (Sandbox Code Playgroud)

主tkinter窗口最小工作示例:

import tkinter as tk

root = tk.Tk() …
Run Code Online (Sandbox Code Playgroud)

python tkinter splash-screen

2
推荐指数
1
解决办法
8991
查看次数

Splinter-如何单击实现为div或span元素的链接/按钮

我在Python中使用Splinter库。我希望根据链接文本单击链接,但这不起作用。

该链接包含在源代码中,例如:

<a href="link here"><span style="color:#000000;">link text here</span></a>
Run Code Online (Sandbox Code Playgroud)

使用' browser.click_link_by_text('link text here')'会产生错误:

splinter.exceptions.ElementDoesNotExist:找不到带有文本链接的元素“此处链接文本”

python web-scraping splinter

0
推荐指数
1
解决办法
3113
查看次数