我是python和matplotlib库的新手.我使用matplotlib创建了一个散点图,现在我希望在X轴下方添加一个标题.这是我的代码:
from matplotlib import pyplot as plt
import numpy as np
from pylab import *
file = open('distribution.txt', 'r')
txt="I need the caption to be present a little below X-axis"
x=[]
y=[]
for line in file:
new=line.rstrip()
mystring=new.split("\t")
x.append(mystring[0])
y.append(mystring[1])
fig = plt.figure()
ax1 = fig.add_axes((0.1,0.4,0.8,0.5))
ax1.set_title("This is my title")
ax1.set_xlabel('X-axis')
ax1.set_ylabel('Y-axis')
ax1.scatter(x,y, c='r')
fig.text(.05,.05,txt)
plt.xlim(0, 1.05)
plt.ylim(0, 2.5)
plt.show()
Run Code Online (Sandbox Code Playgroud)
正如您在图像中看到的,我的标题位于散点图下方,是否有办法将其精确地置于X轴下方?我的散点图看起来也是矩形的,有没有办法让它像方块一样?
我试图找到一个查询,告诉我不在我的数据库中的值.例如:
select seqID, segment from flu where seqID IN (1,2,3,4,5,6,7,8,9).
Run Code Online (Sandbox Code Playgroud)
现在如果我的数据库没有seqID的3,8,9我怎么才能找到/只显示缺少的seqID.
我正在使用heatmap.2制作热图,并想知道是否还有在所有热图位置上显示值.例如,对于表示"1"和等级的区域,我想显示值"43",表示"2",并将值51赋予特权等等.
我的样本数据如下: 
rating complaints privileges learning raises critical advance
1 43 51 30 39 61 92 45
2 63 64 51 54 63 73 47
3 71 70 68 69 76 86 48
4 61 63 45 47 54 84 35
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用散列哈希与数组值概念生成哈希.我不确定我的语法是否正确.
下面是我希望应该创建具有数组值的哈希哈希值的代码部分.
use strict;
%hash=();
open IN, "samplefile.txt" or die "cannot open file:$!";
while(<IN>){
chomp $_;
my @split=split("\t", $_);
$hash{$split[0]}{$split[1]}=push @{ $hash{$split[0]}{$split[1]} },$split[2];
push(@array, $split[1]);
}
Run Code Online (Sandbox Code Playgroud)
样本数据集:
4 10 2
9 4 3
4 3 2
4 3 8
4 10 5
4 5 2
Run Code Online (Sandbox Code Playgroud)
期待哈希.
%hash=(
'4'=> {
'10'=>'2, 5'
'5' => '2'
'3' => '2,8'
}
'9'=>{
'4'=>'3'
}
)
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用库绘制点图ggplot2.我的脚本为下面的示例数据生成一个点图,但我要求点边框着色,但点的其余部分应为空(无填充).例如,如果我的点是红色,蓝色和绿色,我只想让点边框为红色,蓝色和绿色,而点的其余部分应为空.
以下是我当前的脚本和示例数据
library(ggplot2)
File2=read.table("PB12_combo.txt", header=T, sep="\t")
ggplot(File2, aes(x_axis, y_axis, colour=factor(z_axis)))+geom_point(size=5)
x_axis y_axis z_axis
605 250 2
690 394 2
762 109 2
543 495 2
388 538 2
758 736 2
197 409 2
390 106 3
390 343 4
Run Code Online (Sandbox Code Playgroud) 我正在尝试将 Rcpp 从 1.0.6 更新到 1.0.7 或 1.0.8。Rcpp 更新对于我打算使用的主要 R 库至关重要。
\n我查看了文档并尝试使用以下命令安装 Rcpp:
\ninstall.packages("Rcpp", repos="https://RcppCore.github.io/drat")\nRun Code Online (Sandbox Code Playgroud)\n安装已完成,但更新未发生。我附上了以下命令和sessionInfo()信息:
library(Seurat)\n Error: package or namespace load failed for \xe2\x80\x98Seurat\xe2\x80\x99 in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):\nnamespace \xe2\x80\x98Rcpp\xe2\x80\x99 1.0.6 is already loaded, but >= 1.0.7 is required\n\n> sessionInfo()\nR version 4.0.2 (2020-06-22)\nPlatform: x86_64-pc-linux-gnu (64-bit)\nRunning under: Red Hat Enterprise Linux Server release 6.7 (Santiago)\n\nMatrix products: default\nBLAS: /usr/lib64/libblas.so.3.2.1\nLAPACK: /usr/lib64/liblapack.so.3.2.1\n\nRandom number generation:\nRNG: Mersenne-Twister \nNormal: Inversion \nSample: Rounding \n\n locale:\n[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C …Run Code Online (Sandbox Code Playgroud) 我试图将数组和标量传递给子程序.但阵列解除引用似乎存在问题.以下是我的代码
use strict;
use warnings;
my @arr=("95,100", "102,65", "92,34");
my $len=100;
avg($len,\@arr);
sub avg{
my $len = shift;
my $array=@_;
my @new=@{$array};
print @new,"\n";
}
Run Code Online (Sandbox Code Playgroud)
print语句打印此警告:
Can't use string ("1") as an ARRAY ref while "strict refs" in use at test_arr.pl line 13.
Run Code Online (Sandbox Code Playgroud) 我通过读取文本文件创建了一个数据框.我很想知道特定列中是否存在少量值,如果它们存在,我想打印整行.
这是我的输入文件(analyte_map.txt):
Analyte_id mass Intensity
A34579 101.2 786788
B12345 99.2 878787
B943470 103.89 986443
C12345 11.2 101
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import pandas as pd
map_file="analyte_map.txt"
array=['A34579','B943470','D583730']
analyte_df=pd.read_table(map_file,sep="\t")
for value in array:
if analyte_df.lookup([value],['Analyte_id']):
print '%s\t%s'%(analyte_df['mass'],analyte_df['Intensity'])
Run Code Online (Sandbox Code Playgroud) r ×3
perl ×2
arrays ×1
dataframe ×1
ggplot2 ×1
heatmap ×1
indexing ×1
matplotlib ×1
pandas ×1
plot ×1
postgresql ×1
python ×1
rcpp ×1
subroutine ×1