2017-06-03 50 views
1

所以这是一个简化版本,但你可以看到我创建matplotlib的图形和显示。我用'gray21'来显示它,它已经用于Tkinter对象,但它不在这里工作。颜色'白'是我发现的唯一一个可行的。我怎样才能获得各种颜色?我可以使用RGB或某种形式的精确颜色规格,因为我记住了一种颜色(R:70 G:70 B:70)。 .patch.set_facecolor()采用什么形式的颜色?问题与matplotlib接受不同的颜色形成

import matplotlib.pyplot as plt 
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg 
from Tkinter import * 


root=Tk() 
root.geometry('1000x700') 
root.configure(bg="gray21") 
root.title("My Graph") 


one_day_fig=plt.figure() 

one_day_fig.patch.set_facecolor('gray21') 
plt.plot([1,2,3], [2,4,6]) 
my_canvas = FigureCanvasTkAgg(one_day_fig,master=root) 
plot_widget = my_canvas.get_tk_widget() 
plot_widget.place(x=50, y=50) 


root.mainloop() 
+1

http://matplotlib.org/users/colors.html – Goyo

+0

@Goyo所以说,RGB需要3个数字,所以如果我的RGB值是70,70,70,不会我one_day_fig。 patch.set_facecolor(.7,.7,.7)?但是这并没有奏效。我错过了什么? – Addison

+1

您是否阅读过错误信息?还有什么是“浮点值的RGB或RGBA元组”。 – Goyo

回答

1

RGB值可以指定为0和255之间的整数的3元组或作为漂浮的0和1

元组之间3元组(70,70,70)将因此对应于(70/255., 70/255., 70/255.)

这可以被用作彩色规格来matplotlib。

figure.set_facecolor((70/255., 70/255., 70/255.)) 
+0

啊谢谢你!你会碰巧知道如何改变我的x和y轴的字体颜色? – Addison

+0

这不是在这里聊天。如果您有任何问题,请提出问题。但要确保这个问题还没有被问到。正如你可以想象你不是第一个想要改变阴谋的颜色,所以可能[这是问题](https://stackoverflow.com/questions/14165344/matplotlib-coloring-axis-tick-标签)你以后?! – ImportanceOfBeingErnest