我想将拟合模型的 PDFgamma(lambda,k)与直方图叠加。我写的 :
hist(pressure)
curve(dgamma(x, lambda, k), add=TRUE, col="red")
Run Code Online (Sandbox Code Playgroud)
但我对“x”的值是什么感到困惑。有人帮忙吗?
我制作了一个看起来像这样的直方图:
我用来生成这个图的代码:
sns.countplot(table.column_name)
Run Code Online (Sandbox Code Playgroud)
如您所见,由于数据分布不均,整个直方图聚集在左端。
如何在左端放大?
我尝试过的一种方法,它给了我稍微好一点的结果:
plt.xlim(0,25)
Run Code Online (Sandbox Code Playgroud)
有一个更好的方法吗?
问题都在标题中。我正在尝试使用从 bokeh.charts 导入的 Histogram 对象,但无法弄清楚如何以对数比例显示它。在我的特殊情况下,我需要以对数刻度显示 x 轴和 y 轴。
我有以下动画子图模拟四种不同分布的直方图:
import numpy
from matplotlib.pylab import *
import matplotlib.animation as animation
n = 100
# generate 4 random variables from the random, gamma, exponential, and uniform distributions
x1 = np.random.normal(-2.5, 1, 10000)
x2 = np.random.gamma(2, 1.5, 10000)
x3 = np.random.exponential(2, 10000)+7
x4 = np.random.uniform(14,20, 10000)
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
def updateData(curr):
if curr == n:
a.event_source.stop()
ax1.hist(x1[:curr], normed=True, bins=20, alpha=0.5)
ax2.hist(x2[:curr], normed=True, bins=20, alpha=0.5)
ax3.hist(x3[:curr], normed=True, bins=20, alpha=0.5)
ax4.hist(x4[:curr], normed=True, bins=20, alpha=0.5)
simulation = animation.FuncAnimation(fig, updateData, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 python 中的图像切片器分割图像,然后对每个图像应用直方图均衡化并将它们组合回来。我能够将图像分成更小的块,我可以看到它们正在更新,但在将它们拼接在一起后,我最终得到了与原始图像相同的图像。有人可以指出我做错了什么。文件名为 watch.png
import cv2
import numpy as np
from matplotlib import pyplot as plt
from scipy.misc import imsave
# import scipy
from scipy import ndimage
from scipy import misc
import scipy.misc
import scipy
import sys
import argparse
import image_slicer
from image_slicer import join
img = 'watch.png'
num_tiles = 64
tiles = image_slicer.slice(img, num_tiles)
file = "watch"
k = 0
filelist =[]
for i in range(1,9):
for j in range(1,9):
filelist.insert(k, file+"_"+str(i).zfill(2)+"_"+str(j).zfill(2)+".png")
k=k+1
for i in range(0,num_tiles):
img = …Run Code Online (Sandbox Code Playgroud) 我试图通过反复试验来理解 Quiver,但我的数学不是那么重要。我想知道是否有人可以对此有所了解。
我有一个直方图作为这样的矩阵:
magnitude, angle = [[3,2,4,3,9], [x,x,x,x,x]]
Run Code Online (Sandbox Code Playgroud)
角度尚未确定,但在直方图上,角度是分档,幅度是 Y。第一个分档将代表圆的前 1/5,因此是那里的角度。
然而,为什么我还没有填充角度的问题是因为我想用 plt.quiver 从一个点绘制 5 条线/向量。
plt.quiver(x,y,u,v)
Run Code Online (Sandbox Code Playgroud)
X 和 Y 不言自明,但我无法弄清楚 u 和 v 代表什么。文档也没有说太多。我需要从同一点以直方图中给出的特定角度和幅度绘制 5 条线,但我无法让它工作。我什至以正确的方式使用该功能吗?谢谢 !!
顺便说一句,我正在制作一个猪(梯度直方图),结果应该是这样的:
我有这个用熊猫制作的情节:
我想在情节的标题和以下情节的轴之间有更多的空间,这样它们就不会重叠。我已经尝试了问题的解决方案,使用 matplotlib 中的许多子图改善子图大小/间距,但没有一个对我的图没有任何影响。
我想使用 matplotlib.pyplot 作为直方图在 python 上绘制以下字典。我该如何编码?
{'G': 198, 'T': 383, 'C': 260, 'A': 317}
Run Code Online (Sandbox Code Playgroud) 我有一个特别的问题。我将尝试尽可能准确地描述这一点。
我正在做一个非常重要的“微优化”。一次运行数天的循环。所以如果我能减少这个循环时间,它需要一半的时间。10 天将减少到只有 5 天等。
我现在拥有的循环是函数:“testbenchmark1”。
我有 4 个索引需要在这样的循环中增加。但是当从列表中访问索引时,实际上需要一些额外的时间,正如我所注意到的。这就是我想知道是否有其他解决方案。
indexes[n]++; //increase correct index
“testbenchmark1”的完整代码需要 122 毫秒:
void testbenchmark00()
{
Random random = new Random();
List<int> indexers = new List<int>();
for (int i = 0; i < 9256408; i++)
{
indexers.Add(random.Next(0, 4));
}
int[] valueLIST = indexers.ToArray();
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
int[] indexes = { 0, 0, 0, 0 };
foreach (int n in valueLIST) //Takes 122 ms
{
indexes[n]++; //increase correct index
}
stopWatch.Stop();
MessageBox.Show("stopWatch: " + stopWatch.ElapsedMilliseconds.ToString() …Run Code Online (Sandbox Code Playgroud) 我想通过在使用 ggplot2 生成的直方图中添加矩形来为背景着色。不幸的是,我的直方图没有绘制,我不明白为什么。

这是我的代码,感谢您的帮助:
##### DATA FOR HISTROGRAM
chr = 1:11
nb_SNP = 1000
SNP_positions <- data.frame()
for(c in chr){
for(n in 1:nb_SNP){
position <- sample(1:5000000, 1)
SNP_positions <- rbind(SNP_positions,data.frame(chr = chr, position = position))
}
}
##### DATA FOR RECTANGLE
df_chr <- data.frame(chr=c(1:11),
xmin = rep(1,11),
xmax = c(40297282, 64237462, 80088348, 41978404, 74731017, 53893726, 52447651, 74330457, 39019482, 39359118, 45510589))
#### MAKE PLOT
MarkerDensity <- ggplot(SNP_positions) +
geom_rect(data = df_chr, aes(xmin = xmin, xmax = xmax, fill = as.factor(chr)),ymin = …Run Code Online (Sandbox Code Playgroud)