我尝试在我创建的图中添加一个小摘要表ggplot2::ggplot().该表将添加gridExtra::tableGrob()到已保存的ggplot对象.
我的问题是,这似乎改变了我原始情节的y限制.有没有办法避免这种情况而不必再通过指定限制ylim()?
以下是使用ChickWeight数据集的问题的最小示例:
# load packages
require(ggplot2)
require(gridExtra)
# create plot
plot1 = ggplot(data = ChickWeight, aes(x = Time, y = weight, color = Diet)) +
stat_summary(fun.data = "mean_cl_boot", size = 1, alpha = .5)
plot1
# create table to add to the plot
sum_table = aggregate(ChickWeight$weight,
by=list(ChickWeight$Diet),
FUN = mean)
names(sum_table) = c('Diet', 'Mean')
sum_table = tableGrob(sum_table)
# insert table into plot
plot1 + annotation_custom(sum_table)
Run Code Online (Sandbox Code Playgroud)
编辑:
我只是发现它似乎是一个问题stat_summary().当我使用另一个geom/layer时,限制将保持原始图中的限制.另一个例子:
plot2 = ggplot(data = …Run Code Online (Sandbox Code Playgroud) 我有一个继承pyside-uic生成的python类的对话框类,但我的问题是它无法扩展我添加另一个基类.
import sys
from PySide import QtGui
from mi_ui import Ui_Dialog
class Worker(object):
def __init__(self):
super(Worker, self).__init__()
self.data = 1
class MainDialog(QtGui.QDialog, Ui_Dialog, Worker):
def __init__(self):
super(MainDialog, self).__init__()
self.setupUi(self)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
dlg = MainDialog()
print dlg.data
dlg.show()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)
当我尝试扩展MainDialog时Worker,super不调用Worker's __init__和print dlg.data失败,因为"AttributeError:'MainDialog'对象没有属性'data'"
我唯一的解决方法似乎是忽略super并__init__手动调用每个.
QtGui.QDialog.__init__(self)
Worker.__init__(self)
Run Code Online (Sandbox Code Playgroud)
这是我唯一的解决方案吗?
这适用于Python 2.7.