我目前正在编写一个代码,该代码将连续地通过串行通信检索绘图数据,同时还允许用户以raw_input的形式输入以控制作业,例如开始/停止/清除绘图并设置保存文件名。数据。 当前,我正在尝试通过一个额外的线程来做到这一点,该线程将在连续绘制和保存数据时读取用户输入并将其中继到程序。 不幸的是 ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我正在尝试用python编写一个程序,该程序将接受用户输入以在matplotlib中设置甜甜圈饼图的颜色。 这是我目前正在工作的东西:
#3 ring 3 - Factors
mypie4, _ =ax.pie(factor_size, radius=5-1.4, colors=[a(0.85), a(0.85),
g(0.0), a(0.85),
g(0.0),
b(0.7), b(0.7), b(0.7),
c(0.85), c(0.85),
c(0.85), c(0.85),
g(0.0), g(0.0),
d(0.85), d(0.85),
g(0.0)])
plt.setp(mypie4, width=.2, edgecolor='black')
plt.margins(0,0)
这是我想发生的事情:
## Show menu ##
print (30 * '-')
print (" Color Choices for First Quadrant")
print (30 * '-')
print ("1. Blue")
print ("2. Orange")
print ("3. Green")
print ("4. Purple")
print (30 * '-')
## Get input ###
choice = raw_input('Enter your choice [1-4] : ')
### Convert string to int type ##
choice = int(choice)
### Take action as per selected menu-option ###
if choice == 1:
user_color = [plt.cm.Blues(0.75)]
elif choice == 2:
user_color = [plt.cm.Oranges(0.75)]
elif choice == 3:
user_color = [plt.cm.Greens(0.75)]
elif choice == 4:
user_color = [plt.cm.Purples(0.75)]
else: ## default ##
print ("Invalid number. Try again...")
#3 ring 3 - Factors
mypie4, _ =ax.pie(factor_size, radius=5-1.4, colors=[[user_color],
[user_color],
[user_color],
[user_color],
[user_color],
b(0.7), b(0.7), b(0.7),
c(0.85), c(0.85),
c(0.85), c(0.85),
g(0.0), g(0.0),
d(0.85), d(0.85),
g(0.0)])
plt.setp(mypie4, width=.2, edgecolor='black')
plt.margins(0,0)
我不知道如何将变量调用到ax.pie的colors属性中。 使用这种格式,我可以对其他象限执行相同的操作。 随附的是我手动制作的最终照片。 我希望能够自动产生这些颜色。 甜甜圈色象限轮
您需要将颜色放入单个阵列中。 您生成了多个数组,每个数组都有一个值。
首先,您需要将所有象限的用户输入保存到单个数组中。 因此,您可以使用以下功能:
def getQuadrantColor(colorList, quadrantName):
print (30 * '-')
print (" Color Choices for {} Quadrant".format(quadrantName))
print (30 * '-')
print ("1. Blue")
print ("2. Orange")
print ("3. Green")
print ("4. Purple")
print (30 * '-')
## Get input ###
choice = raw_input('Enter your choice [1-4] : ')
### Convert string to int type ##
choice = int(choice)
### Take action as per selected menu-option ###
if choice == 1:
colorList.append(plt.cm.Blues(0.75))
elif choice == 2:
colorList.append(plt.cm.Oranges(0.75))
elif choice == 3:
colorList.append(plt.cm.Greens(0.75))
elif choice == 4:
colorList.append(plt.cm.Purples(0.75))
else: ## default ##
print ("Invalid number. Try again...")
getQuadrantColor(colorList, quadrantName)
您现在可以使用此功能,例如
colorList = []
quadrants = ["First", "Second", "Third", "Fourth"]
for quadrant in quadrants:
getQuadrantColor(colorList, quadrant)
现在您获得了所有颜色信息,可以创建饼图
mypie4, _ =ax.pie(factor_size, radius=5-1.4, colors=colorList)
plt.setp(mypie4, width=.2, edgecolor='black')
plt.margins(0,0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.