我正在测试一个算法,我想用matplotlib生成一系列显示中间结果的数字.
我不需要动画,也不需要屏幕上的多个数字,也不需要子图.
我只想制作一系列数字(可能使用pyplot),当我完成时,会显示一个窗口.然后我想用箭头在数字序列中导航.
我怎么能这样做?
我试图搜索,但我只能在屏幕上找到子图或多个数字.
谢谢
我有一个关于matplotlib条的问题.我已经制作了一些条形图,但我不知道为什么,这个在顶部留下了一个巨大的空白区域.
代码类似于我制作的其他图形,他们没有这个问题.
如果有人有任何想法,我感谢你的帮助.
x = matplotlib.numpy.arange(0, max(total))
ind = matplotlib.numpy.arange(len(age_list))
ax.barh(ind, total)
ax.set_yticks(ind)
ax.set_yticklabels(age_list)
Run Code Online (Sandbox Code Playgroud) 虽然每个周期的持续时间和内容在某些参数内略有不同,但我有一个重复信号,每个周期大约每秒重复一次.每秒信号数据都有一千个x,y坐标.每个周期内的一小部分但重要的数据部分已损坏,我想用向上的抛物线替换每个损坏的部分.
对于需要由抛物线替换的每个数据段,我有三个点的x,y坐标.顶点/最小值是这些点之一.另外两个点是向上U形的左右顶部,即抛物线.换句话说,左上角是此函数域中最低x值的x,y坐标对,而右上角是此函数域中最高x值的x,y坐标对.左上顶部和右上顶部的y坐标彼此相等,并且是数据段中的两个最高y值.
如何编写代码来绘制这个面向上的抛物线的剩余数据点? 请记住,对于每分钟的数据,此函数需要调用60或70次,并且每次调用此函数时抛物线的形状/公式都需要更改,以便考虑这三对之间的不同关系.每个得到的抛物线中的x,y坐标.
def ReplaceCorruptedDataWithParabola(Xarray, Yarray, LeftTopX, LeftTopY
, LeftTopIndex, MinX, MinY, MinIndex
, RightTopX, RightTopY, RightTopIndex):
# Step One: Derive the formula for the upward-facing parabola using
# the following data from the three points:
LeftTopX,LeftTopY,LeftTopIndex
MinX,MinY,MinIndex
RightTopX,RightTopY,RightTopIndex
# Step Two: Use the formula derived in step one to plot the parabola in
# the places where the corrupted data used to reside:
for n in Xarray[LeftTopX:RightTopX]:
Yarray[n]=[_**The formula goes here**_]
return Yarray
Run Code Online (Sandbox Code Playgroud)
注意:Xarray和Yarray都是单列向量,每个索引都有数据,将两个数组链接为x,y坐标集.它们都是numpy数组.Xarray包含时间信息并且不会更改,但Yarray包含信号数据,包括将被需要由此函数计算的抛物线数据替换的损坏段.
在 matplotlib 中,我在轴上保留一个参考。如果包含轴的窗口已关闭,我想打开一个新图形。这个想法是继续在图形上添加绘图,直到它关闭,然后我打开一个新图形。请注意,新图的创建是由另一个图中的事件触发的。
如果它可以帮助您理解我正在尝试做的事情,这里是课程:
class DetailedPlot(object):
def __init__(self, figure):
self.origin_figure = figure
self.axis = None
self.print_figure = None
self.origin_figure.canvas.mpl_connect('button_press_event', self)
def __call__(self, event):
if event.xdata is None or event.ydata is None:
return
r = round(event.xdata - 0.025, 1)
l = round(event.ydata - 0.025, 1)
if self.axis is None or self.axis.belongs_to_a_closed_window():
self.print_figure = plt.figure()
self.axis = self.print_figure.add_subplot(111)
plotting_fcn(self.axis, r, l)
Run Code Online (Sandbox Code Playgroud)
我的目标是找到一个函数,例如belongs_to_a_closed_window
我正在尝试计算由某列标识的两个数据集的平均值.这是AA2栏.简单的解决方案是首先识别数据集,然后计算该数据集的平均值.然而,这在python中看起来并不好看.numpy有没有办法为我做这件事?
我的数据集:
Run Code Online (Sandbox Code Playgroud)Number AA1 AA2 AA3 Atom amou mean_shift stddev 187 ALA GLU LEU C 1 119.47 0.00 187 ALA GLU LEU O 1 8.42 0.00 188 ALA GLU LYS C 1 120.67 0.00 188 ALA GLU LYS O 1 9.11 0.00 777 ARG GLN ARG C 1 117.13 0.00 777 ARG GLN ARG O 1 8.48 0.00
我想要的是:
Run Code Online (Sandbox Code Playgroud)187 GLU C 1 (119.47+120.67+117.13)/3 0.00 187 GLU O 1 (8.42+9.11+8.48)/3 0.00
编辑:我清理了这个例子.均值是在列mean_shift上计算的,但仅在原子相同的行上计算.我的(不太好的版本)是这样的:
i,j = 0,0
# iterate over all keys …Run Code Online (Sandbox Code Playgroud) 我正在使用 matplotlib 运行动画FuncAnimation以显示来自微处理器的数据(实时)。我正在使用按钮向处理器发送命令,并希望按钮的颜色在被点击后改变,但我在matplotlib.widgets.button文档中(目前)找不到任何可以实现这一点的内容。
class Command:
def motor(self, event):
SERIAL['Serial'].write(' ')
plt.draw()
write = Command()
bmotor = Button(axmotor, 'Motor', color = '0.85', hovercolor = 'g')
bmotor.on_clicked(write.motor) #Change Button Color Here
Run Code Online (Sandbox Code Playgroud) 我有一个2D数组,在这里我试图绘制一列中所有行的直方图,给定另一列中的条件.我试图在plt.hist()命令中选择子数据,以避免产生许多子数组,我已经知道如何做.例如,如果
a_long_named_array = [1, 5]
[2, 6]
[3, 7]
Run Code Online (Sandbox Code Playgroud)
我可以通过写入创建我的数组的子集,使第1列大于5
a_long_named_subarray = a_long_named_array[a_long_named_array[:,1] > 5]
Run Code Online (Sandbox Code Playgroud)
如何在不制作上述子阵列的情况下绘制此子数据?请看下面.
import numpy as np
import matplotlib.pyplot as plt
#Generate 2D array
arr = np.array([np.random.random_integers(0,10, 10), np.arange(0,10)])
#Transpose it
arr = arr.T
#----------------------------------------------------------------------------
#Plotting a Histogram: This works
#----------------------------------------------------------------------------
#Plot all the rows of the 0'th column
plt.hist(arr[:,0])
plt.show()
#----------------------------------------------------------------------------
#Plotting a conditional Histogram: This is what I am trying to do. This Doesn't work.
#----------------------------------------------------------------------------
#Plot all the rows of the 0th column where …Run Code Online (Sandbox Code Playgroud) 我有一系列来自视频流的图像,我想用Matplotlib(灰度)显示.出于某种原因,我可以让它们完美地显示颜色,但是当我将它们转换为灰度时则不能.
由于我有很多图像,我使用set_data( image )而不是imshow( image )因为它更快.使用这两个命令可以很好地处理彩色图像,但灰度图只适用于imshow().如果我使用set_data()我只是得到一个黑色图像,无论我发送什么数据.
知道这可能会发生什么吗?
我的代码在下面供参考.我用重要的评论突出了重要的一点,但是我已经包含了所有其他代码,以防其他因素导致问题.其余的代码基本上建立了一个队列,其中填充了来自摄像头的图像,我希望在我得到它们时显示它们.
import matplotlib.pyplot as plt
from matplotlib import cm
from cv_bridge import CvBridge, CvBridgeError
import cv
from collections import deque
import rospy
from sensor_msgs.msg import Image
import numpy as np
class CameraViewer():
def __init__( self, root='navbot' ):
self.root = root
self.im_data = deque()
self.bridge = CvBridge() # For converting ROS images into a readable format
self.im_fig = plt.figure( 1 )
self.im_ax = self.im_fig.add_subplot(111)
self.im_ax.set_title("DVS Image") …Run Code Online (Sandbox Code Playgroud) scikit-learn有一个非常好的演示,可以创建异常分析工具.这里是
import numpy as np
import pylab as pl
import matplotlib.font_manager
from scipy import stats
from sklearn import svm
from sklearn.covariance import EllipticEnvelope
# Example settings
n_samples = 200
outliers_fraction = 0.25
clusters_separation = [0, 1, 2]
# define two outlier detection tools to be compared
classifiers = {
"One-Class SVM": svm.OneClassSVM(nu=0.95 * outliers_fraction + 0.05,
kernel="rbf", gamma=0.1),
"robust covariance estimator": EllipticEnvelope(contamination=.1)}
# Compare given classifiers under given settings
xx, yy = np.meshgrid(np.linspace(-7, 7, 500), np.linspace(-7, 7, 500))
n_inliers …Run Code Online (Sandbox Code Playgroud) 颜色条与我放置在图像上的轮廓图具有相同的透明度。
我可以通过在最低的“zorder”位置添加一个没有透明度的假轮廓图来实现不透明的颜色条,但我想有一种正确的方法吗?
这给了我一个半透明的颜色条:
cs = m.contourf(xv,yv,zi,zorder=4,alpha=0.7,origin="lower")
cbar = m.colorbar(cs,location='right',pad="5%")
Run Code Online (Sandbox Code Playgroud) 列表中的每个项目的第二个列表,xs.运行下面的代码,python给我'无'
xs = [12, 10, 32, 3, 66, 17, 42, 99, 20]
a = [b**2 for b in xs]
c = (a + xs).sort()
print(c, end=', ')
Run Code Online (Sandbox Code Playgroud)
相同的列表但不同的代码 -
xs = [12, 10, 32, 3, 66, 17, 42, 99, 20]
a = [b**2 for b in xs]
c = a + xs
c.sort()
print(c, end=', ')
Run Code Online (Sandbox Code Playgroud)
... python给了我列表(c),全部排序.我不明白.或者有更多的pythonic方式来做到这一点?
谢谢!
python ×11
matplotlib ×8
numpy ×4
python-3.x ×2
animation ×1
button ×1
django ×1
image ×1
python-2.7 ×1
scipy ×1
tkinter ×1