我已经加入annotate-models我的:development小组,删除Gemfile.lock,运行bundle install,但它仍然会中断.
$ annotate User
/usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/polyglot-0.3.1/lib/polyglot.rb:64:in `polyglot_original_require': no such file to load -- annotate/annotate_models (LoadError)
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/polyglot-0.3.1/lib/polyglot.rb:64:in `require'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/annotate-2.4.0/lib/tasks/annotate_models.rake:3
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/1.8/monitor.rb:242:in `synchronize'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/lib/ruby/gems/1.8/gems/annotate-2.4.0/bin/annotate:67
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/bin/annotate:19:in `load'
from /usr/local/Cellar/ruby-enterprise-edition/2010.02/bin/annotate:19
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
几个小时以来,我一直在挠头。我现在所拥有的:
library(ggplot2)
library(grid)
all_data = data.frame(country=rep(c("A","B","C","D"),times=1,each=20),
value=rep(c(10,20,30,40),times=1,each=20),
year = rep(seq(1991,2010),4))
# PLOT GRAPH
p1 <- ggplot() + theme_bw() + geom_line(aes(y = value, x = year,
colour=country), size=2,
data = all_data, stat="identity") +
theme(plot.title = element_text(size=18,hjust = -0.037), legend.position="bottom",
legend.direction="horizontal", legend.background = element_rect(size=0.5, linetype="solid", colour ="black"),
legend.text = element_text(size=16,face = "plain"), panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.border = element_blank(),axis.line = element_line(colour = "black"),legend.title = element_blank(),
axis.text=element_text(size=18,face = "plain"),axis.title.x=element_text(size=18,face = "plain", hjust = 1,
margin = margin(t = 10, r = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用ImageMagick将文本添加到图像。我看到了多个使用draw,label,caption,annotate等的示例。两者之间有什么区别?我可以使用CLI测试上述命令的结果,但是在尝试使用IM4java由java运行时遇到了麻烦。Java代码段的任何帮助将非常有用。
我正在尝试通过 ggplot2 在 R 中注释一个矩形,以获得对数刻度的图形。这是我要添加的注释层:
annotate("rect",xmin=293.3, xmax=312, ymin=-Inf, ymax=Inf, fill='gray')
Run Code Online (Sandbox Code Playgroud)
当然,我知道负无穷大会引起问题,因为它是对数标度并且没有负值。由于我预先指定了 y 尺度的限制,有人对如何使用此方法或其他方法创建“负无穷大”到无穷大矩形有任何想法吗?
我可以根据内容获取日志吗?
假设我想知道是谁介绍了函数的代码,我将不得不检查日志及其注释(签入消息).如果有人忘记输入日志消息,我将不得不检查每个差异,这将花费很多时间.
像FishEye这样的工具能做到吗?
我正在创建图表,其中一条白线在条形前面打破了条形(抱歉无法发布图像)。我已经得到了一次执行此操作的代码,但我还不擅长循环。
library(ggplot2)
count <- c(61.8,18.8)
name <- c("A","B")
yes <- data.frame(count,name)
j <- ggplot(yes, aes(x=name, y=count)) +
geom_bar(stat="identity", position="dodge")
Run Code Online (Sandbox Code Playgroud)
为了仅添加一行,我创建了这个函数......
b <- function (yx){
j + annotate("segment", x=-Inf, xend=Inf, y=yx, yend=yx,size=1, colour="white")
}
b(8)
Run Code Online (Sandbox Code Playgroud)
这就是我陷入困境的地方,我想制作一个可以遍历向量的循环,例如......
yx <- c(8,10,20)
Run Code Online (Sandbox Code Playgroud)
并在 8、10 和 20 处创建一行。一个棘手的问题是,除了终端数据(最后一个)之外的所有数据都需要在末尾有一个“+”。有人试过这个吗?
谢谢
我有一个锤子投影图,我试图在图的中心添加文本(纬度 = 0,经度 = 0)。由于某种原因,字符串“0”绘制在图的左下角。
我有以下代码。
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
#data points
ra = [25,20,21]
dec = [25,20,21]
fig = plt.figure()
ax = fig.add_axes([0.1,0.1,0.8,0.8])
# Get the hammer projection map
m = Basemap(projection='hammer',lon_0 = 0, rsphere = 1.0)
m.drawparallels(np.arange(-90.,90.,30.),labels=[1,0,0,0]) # draw parallels
m.drawmeridians(np.arange(-180.,180.,60.)) # draw meridians
m.plot(ra,dec,marker='o',linestyle='None',markersize=1,latlon=True)
ax.annotate('0', xy=(0, 0), xycoords='data',xytext = (0,0),textcoords='data')
plt.show()
Run Code Online (Sandbox Code Playgroud)
我还附上了该图,很明显,字符“0”的位置位于错误的位置。有任何想法吗?
我想添加一个包含变量的公式作为我的 ggplot 上的注释。
regline1 <- 0.00
slope1 <- 1.00
dat <- as.data.frame(c(0,1))
dat[2] <- c(0,1)
names(dat) <- c("foo","bar")
p <-
ggplot(dat, aes(foo, bar)) + coord_fixed(ratio = 1) + geom_point() +
geom_abline(slope = slope1, intercept = intercept1, linetype = "dashed") +
labs(x = substitute(y[H1]==i+s%*%x,list(i=format(intercept1, digits = 1), s= format(slope1, digits = 1))))
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,ggplot 计算 labs(x =...) 的公式是没有问题的,但是如果您尝试添加注释:
p + annotate("text",x=0.75, y = 0.25, label = substitute(y[H1]==i+s%*%x,list(i=format(intercept1, digits = 1), s= format(slope1, digits = 1))))
Run Code Online (Sandbox Code Playgroud)
它会给你一个错误:
Error: Aesthetics must be either length …Run Code Online (Sandbox Code Playgroud) 我正在尝试根据促销进行一些复杂的排序:自创建以来每 7 天促销一篇文章(文章在 30 天后过期)。
我的方法是用自创建以来的天数来注释查询集,但days_since_creation在我的代码中,注释字段 ( )的值始终为 0。
from datetime import timedelta
from django.test import TestCase
from django.db.models import ExpressionWrapper, F
from django.db.models.fields import IntegerField
from django.utils import timezone
from .models import Article
# class Article(models.Model):
# title = models.CharField(max_length=150)
# creation_date = models.DateTimeField()
#
# def __str__(self):
# return self.title
class ArticleTestCase(TestCase):
def test_days_since_creation(self):
now = timezone.now()
objects_data = [
Article(
title='Alrp',
creation_date=(now - timedelta(days=5)) # 5 days ago
),
Article(
title='Bopp',
creation_date=(now - timedelta(days=7)) # …Run Code Online (Sandbox Code Playgroud) 我的 Django 模型(作者)中有一个出生日期 ( dob ) DateField 。我尝试注释年龄参数。我搜索了许多可能的方法来做到这一点,每个过程都会产生某种错误。
在这里,我首先在 python 控制台中尝试确保表达式是有效的:
>>> from datetime import datetime
>>> (datetime.now() - datetime(2000,1,1)).days #output: 7506
Run Code Online (Sandbox Code Playgroud)
第一次尝试:
>>> from django.db.models import F
>>> authors = Author.objects.annotate(age = (datetime.now()-F('dob')).days) #no-error here
>>> print(authors) # Exception thrown here
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/puru/Documents/Python/django/prac1/django-master/lib/python3.7/site-packages/Django-3.2-py3.7.egg/django/db/models/query.py", line 324, in __getitem__
qs._fetch_all()
File "/home/puru/Documents/Python/django/prac1/django-master/lib/python3.7/site-packages/Django-3.2-py3.7.egg/django/db/models/query.py", line 1305, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/puru/Documents/Python/django/prac1/django-master/lib/python3.7/site-packages/Django-3.2-py3.7.egg/django/db/models/query.py", line 70, in __iter__
for row …Run Code Online (Sandbox Code Playgroud)