[(几个月前基本上与此相同:导入matplotlib在heroku上没有名为_tkinter的模块失败 .但是,提供的唯一解决方案似乎不起作用.(不幸的是,我不能评论那里给出的答案,因为我没有足够的StackOverflow信誉.))]
我一直在我的应用程序中使用matplotlib进行策划.一切都在当地很好.但是,当我将我的应用程序推送到Heroku时,我得到错误:
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
Run Code Online (Sandbox Code Playgroud)
我试图绕过Tkinter:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt, mpld3
Run Code Online (Sandbox Code Playgroud)
但是,这仍然会引发同样的错误.
有没有人为此找到了解决方案或者有matplotlib的Heroku应用程序正在运行?我正在运行Python 2.7.13(这也是Heroku在推送应用程序时安装的版本).
我正在尝试从 geom_bar 图中更改图例键的形状。我在网上查看了多个答案,但发现它们在这种情况下不起作用。让我解释一下这个问题:
df1 = data.frame(person = c("person1", "person2", "person3"),
variable = "variable1",
value = c(0.5, 0.3, 0.2))
df2 = data.frame(person = c("person1", "person2", "person3"),
variable = "variable2",
value = c(-0.3, -0.1, -0.4))
Run Code Online (Sandbox Code Playgroud)
我正在尝试制作一侧为负的堆叠条形图。使用 ggplot2 我得到:
library(ggplot2)
ggplot() + geom_bar(data = df1, aes(x = person, y = value, fill = variable), stat = "identity") +
geom_bar(data = df2, aes(x = person, y = value, fill = variable), stat = "identity") +
scale_fill_manual(values = c("steelblue", "tomato"), breaks = c("variable1","variable2"),
labels = …Run Code Online (Sandbox Code Playgroud) 我正在寻找解决此问题的任何方法,无论使用什么软件包。
当前的问题是当您使用保存图像时,绘制的图像会失真ggsave。让我举个例子:
image_links = data.frame(id = c(1,2,3,4,5),
image = c("https://cdn.shopify.com/s/files/1/1061/1924/products/Smiling_Emoji_with_Eyes_Opened_large.png",
"https://cdn.shopify.com/s/files/1/1061/1924/products/Smiling_Emoji_with_Smiling_Eyes_large.png",
"https://cdn.shopify.com/s/files/1/1061/1924/products/Hushed_Face_Emoji_large.png",
"https://cdn.shopify.com/s/files/1/1061/1924/products/Disappointed_but_Relieved_Face_Emoji_large.png",
"https://cdn.shopify.com/s/files/1/1061/1924/products/Expressionless_Face_Emoji_large.png"))
mydata = data.frame(x = rnorm(100, mean = 50, sd = 20),
y = rnorm(100, mean = 50, sd = 5),
id = rep(c(1,2,3,4,5), 20))
mydata$y = mydata$y - 10*mydata$id
mydata = mydata %>% left_join(image_links, by='id')
g <- ggplot(mydata) + geom_image(aes(x=x, y=y, image=image), size=0.05)
ggsave(g, filename='[INSERT PATH HERE].png', width=width, height=height, dpi=300)
Run Code Online (Sandbox Code Playgroud)
调整的width和height参数时会出现问题ggsave,例如,因为您希望x轴和y轴的比例正确:
width = (max(mydata$x) - min(mydata$x))/10
height …Run Code Online (Sandbox Code Playgroud)