- FinCloud
-
cogcreategraphiclabeltool怎么显示坐标
plot()函数默认会绘制坐标轴,当需要单独设置坐标轴时,可以先将axes参数设置为FALSE,再使用axis()进行设置,语法结构如下:
axis(side, at = NULL, labels = TRUE, tick = TRUE, line = NA,
pos = NA, outer = FALSE, font = NA, lty = "solid",
lwd = 1, lwd.ticks = lwd, col = NULL, col.ticks = NULL,
hadj = NA, padj = NA, gap.axis = NA, ...)
登录后复制
side:需要添加坐标轴的位置,1-4分别用于指定底部、左侧、上侧和右侧的坐标轴;
at:需要添加刻度线的位置;
labels:设置是否添加刻度标签;
tick:设置是否显示轴线和刻度线;
line:坐标轴线与边框的行距,同mtext()的同名参数,可忽略;
pos:指定绘制坐标轴线的坐标,可忽略;
outer:为TRUE时以outer margin作为参考;
font、lty、lwd、lwd.ticks、col、col.ticks:美化参数;
hadj、padj:分别用于设置刻度标签与坐标轴线在阅读方向的水平、垂直方向上的距离;
gap.axis:设置刻度标签的最小距离;
...:par()中的相关参数。
plot(sin, 0, 2*pi, type = "l", axes = F)
axis(1, c(0, pi/2, pi, 3*pi/2, 2*pi))
axis(2, c(0, 0.5, 1), labels = F)
axis(3, seq(0, 2*pi, pi/2), tick = F)
axis(4, c(-1, -0.5, 0), line = -2, hadj = 0, col.ticks = "red")
登录后复制
3 图例
R语言的基础绘图系统默认不带图例,需要自定义,相关函数为legend(),语法结构如下:
legend(x, y = NULL, legend, fill = NULL, col = par("col"),
border = "black", lty, lwd, pch,
angle = 45, density = NULL, bty = "o", bg = par("bg"),
box.lwd = par("lwd"), box.lty = par("lty"), box.col = par("fg"),
pt.bg = NA, cex = 1, pt.cex = cex, pt.lwd = lwd,
xjust = 0, yjust = 1, x.intersp = 1, y.intersp = 1,
adj = c(0, 0.5), text.width = NULL, text.col = par("col"),
text.font = NULL, merge = do.lines && has.pch, trace = FALSE,
plot = TRUE, ncol = 1, horiz = FALSE, title = NULL,
inset = 0, xpd, title.col = text.col, title.adj = 0.5,
seg.len = 2)
登录后复制

先绘制一个含有两条曲线的图形:
plot(1:10, sin(1:10), type = "b", pch = 21, col = "red")
lines(1:10, cos(1:10), type = "b", pch = 22, col = "blue")
登录后复制
基本的图例样式
x和y:图例摆放的位置,可以使用坐标,也可以使用如下关键字:"bottomright"、 "bottom"、 "bottomleft"、"left"、 "topleft"、 "top"、"topright"、 "right" 和 "center",此时y缺省;
legend:图例的描述文本;
title:图例标题;
用于区分组别的参数,常见的如形状、颜色等。
plot(1:10, sin(1:10), type = "b", pch = 21, col = "red")
lines(1:10, cos(1:10), type = "b", pch = 22, col = "blue")
legend("bottomleft", legend = c("sin(x)", "cos(x)"), title = "图例",
pch = c(21, 22), lty = 1, col = c("red", "blue"), pt.bg = "white")
登录后复制
用于区分组别的参数
点要素:pch、cex、col、pt.bg、pt.cex、pt.lwd;
线要素:lty、lwd、col;
merge:控制是否将点、线作为整体,默认为TRUE;
面或箱型要素:fill(填充色)、border(边框颜色)。
plot(1, type = "n")
legend("topleft", legend = c("A", "B"),
pch = c(21, 22), lty = 1, col = c("red", "blue"))
legend("topright", legend = c("A", "B"),
pch = c(21, 22), lty = 1, col = c("red", "blue"),
merge = F)
legend("left", legend = c("A", "B"), pch = 21, pt.bg = c("red", "blue"))
legend("right", legend = c("A", "B"), lty = c(1,2), lwd = 2, col = c("red", "blue"))
legend("center", legend = c("A", "B"), fill = c("red", "blue"), border = "green")
登录后复制

设置图例的颜色、边框
bg:图例的背景色;
box.lty、box.lwd、box.col:图例边框的线条类型、宽度和颜色。
plot(1, type = "n")
legend("left", legend = c("A", "B"), fill = c("red", "blue"),
bg = "grey")
legend("right", legend = c("A", "B"), fill = c("grey", "grey"), box.col = c("red", "blue"))
legend("center", legend = c("A", "B"), fill = c("grey", "grey"), box.lty = 2, box.col = "red")
登录后复制
对齐与距离调整
xjust、yjust:图例位置与坐标的对齐方式,xjust默认为0,即左对齐;yjust默认为1,即上对齐;
x.intersp、y.intersp:分别调整图例中水平、垂直方向的间距;
adj:调整图例文本的位置,正数表示向默认位置左侧或下侧调整,负数表示向右侧或上侧调整;
inset:使用关键词设置图例位置时,控制图例边缘与plot side的位置,以plot region长宽的分数表示。
plot(1, type = "n")
legend(0.8, 1, legend = c("A", "B"), fill = c("red", "blue"), bg = "grey",
xjust = 1, yjust = 0)
legend(0.8,1, legend = c("A", "B"), fill = c("grey", "grey"), box.col = c("red", "blue"),
x.intersp = 2, y.intersp = 2)
legend("center", legend = c("A", "B"), fill = c("grey", "grey"), box.lty = 2, box.col = "red",
adj = c(-2, 2))
legend("bottom", legend = c("A", "B"), fill = c("grey", "grey"), box.lty = 2, box.col = "red",
inset = 0.05)
登录后复制
图例文本美化
text.width、text.col、text.font;
title.col、title.adj:图例标题的颜色和水平对齐方式;
ncol:图例内要素列数,默认为1;
horiz:为TRUE时水平方向排列图例要素,此时参数ncol失效。
plot(1, type = "n")
legend("center", legend = c("A", "B"), fill = c("red", "blue"), bg = "grey",
text.col = c("red", "blue"), text.font = 3)
legend("top", legend = c("A", "B"), fill = c("red", "blue"), bg = "grey", title = "图例",
title.col = "green", title.adj = 1)
legend("left", legend = c("A", "B"), fill = c("red", "blue"), bg = "grey",
ncol = 2)
legend("right", legend = c("A", "B"), fill = c("red", "blue"), bg = "grey",
horiz = T)
登录后复制
其他plot:为FALSE时图例不显示。
- 阿啵呲嘚
-
第三处:结果显示
主要就是三个参数信息
#region namespace imports
using System;
using System.Collections;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;
using Cognex.VisionPro3D;
using Cognex.VisionPro.PMAlign;
using Cognex.VisionPro.CalibFix;
using Cognex.VisionPro.Caliper;
#endregion
public class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase
{
#region Private Member Variables
private Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;
//在此处写代码 endregion前,定义变量的地方
//定义一个图形标签
//CogGraphicLabel数据类型 myLabel 变量名 new创建
CogGraphicLabel myLabel = new CogGraphicLabel();
#endregion
/// <summary>
/// Called when the parent tool is run.
/// Add code here to customize or replace the normal run behavior.
/// </summary>
/// <param name="message">Sets the Message in the tool"s RunStatus.</param>
/// <param name="result">Sets the Result in the tool"s RunStatus</param>
/// <returns>True if the tool should run normally,
/// False if GroupRun customizes run behavior</returns>
///
public override bool GroupRun(ref string message, ref CogToolResultConstants result)
{
// To let the execution stop in this script when a debugger is attached, uncomment the following lines.
// #if DEBUG
// if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break();
// #endif
// Run each tool using the RunTool function
foreach(ICogTool tool in mToolBlock.Tools)
mToolBlock.RunTool(tool, ref message, ref result);
// 2.处写代码return false前, 获取工具、工具的运行结果
//获取卡尺工具以及卡尺测量结果 mToolBlock.Tools
//定义卡尺工具 数据类型就是康耐视名字的类型
//中括号为卡尺的名字,要与外侧的名字对应
CogCaliperTool Ruler = new CogCaliperTool();
Ruler = mToolBlock.Tools["CogCaliperTool1"] as CogCaliperTool ;
//以上两行代码的简写 : CogCaliperTool Ruler = mToolBlock.Tools["CogCaliperTool1"] as CogCaliperTool ;
//myLabel.SetXYText(-60,-25,"文字"+Ruler.Results[0].Width.ToString("F3"))
if (Ruler.Results[0].Width < 1196.24){
myLabel.SetXYText(-60,-25,"NG:"+Ruler.Results[0].Width.ToString("F3")); //x坐标,y坐标,显示文字
}
else
{
myLabel.SetXYText(-60,-25,"PASS:"+Ruler.Results[0].Width.ToString("F3")); //x坐标,y坐标,显示文字
}
// 调整颜色
myLabel.Color = CogColorConstants.Red;
// 调整大小
myLabel.Font = new Font("楷体", 15);
return false;
}
#region When the Current Run Record is Created
/// <summary>
/// Called when the current record may have changed and is being reconstructed
/// </summary>
/// <param name="currentRecord">
/// The new currentRecord is available to be initialized or customized.</param>
public override void ModifyCurrentRunRecord(Cognex.VisionPro.ICogRecord currentRecord)
{
}
#endregion
#region When the Last Run Record is Created
/// <summary>
/// Called when the last run record may have changed and is being reconstructed
/// </summary>
/// <param name="lastRecord">
/// The new last run record is available to be initialized or customized.</param>
public override void ModifyLastRunRecord(Cognex.VisionPro.ICogRecord lastRecord)
{
//3.处写代码,定义输出、把结果放在图像上
// AddGraphicToRunRecord中有四个参数:
// 第一个参数:需要放置的图形mylabel、
// 第二个参数:运行记录 一般都是lastRecord
// 第三个参数:放置的位置、图形信息
// 第四个参数:内容可以为空信息
mToolBlock.AddGraphicToRunRecord(
myLabel,
lastRecord,
"CogFixtureTool1.OutputImage",
" "
);
}
#endregion
#region When the Script is Initialized
/// <summary>
/// Perform any initialization required by your script here
/// </summary>
/// <param name="host">The host tool</param>
public override void Initialize(Cognex.VisionPro.ToolGroup.CogToolGroup host)
{
// DO NOT REMOVE - Call the base class implementation first - DO NOT REMOVE
base.Initialize(host);
// Store a local copy of the script host
this.mToolBlock = ((Cognex.VisionPro.ToolBlock.CogToolBlock)(host));
}
#endregion
}
复制
虽然断断续续接触visionpro,但是收获还是挺大的,技多不压身我真的到现在才开始明白真正的含义
结果展示:
妈妈的吻!加密狗被人拔掉了!!我踏马程序还没保存呢! giao! !!罢了罢了,对着视频整,想要加点自己的程序看看我的代码找点思路。
结语:
三连保平安
机器学习
精灵宝可梦4
精选推荐
广告
- CarieVinne
-
第三处:结果显示
主要就是三个参数信息
#region namespace imports
using System;
using System.Collections;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;
using Cognex.VisionPro3D;
using Cognex.VisionPro.PMAlign;
using Cognex.VisionPro.CalibFix;
using Cognex.VisionPro.Caliper;
#endregion
public class CogToolBlockAdvancedScript : CogToolBlockAdvancedScriptBase
{
#region Private Member Variables
private Cognex.VisionPro.ToolBlock.CogToolBlock mToolBlock;
//在此处写代码 endregion前,定义变量的地方
//定义一个图形标签
//CogGraphicLabel数据类型 myLabel 变量名 new创建
CogGraphicLabel myLabel = new CogGraphicLabel();
#endregion
/// <summary>
/// Called when the parent tool is run.
/// Add code here to customize or replace the normal run behavior.
/// </summary>
/// <param name="message">Sets the Message in the tool"s RunStatus.</param>
/// <param name="result">Sets the Result in the tool"s RunStatus</param>
/// <returns>True if the tool should run normally,
/// False if GroupRun customizes run behavior</returns>
///
public override bool GroupRun(ref string message, ref CogToolResultConstants result)
{
// To let the execution stop in this script when a debugger is attached, uncomment the following lines.
// #if DEBUG
// if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break();
// #endif
// Run each tool using the RunTool function
foreach(ICogTool tool in mToolBlock.Tools)
mToolBlock.RunTool(tool, ref message, ref result);
// 2.处写代码return false前, 获取工具、工具的运行结果
//获取卡尺工具以及卡尺测量结果 mToolBlock.Tools
//定义卡尺工具 数据类型就是康耐视名字的类型
//中括号为卡尺的名字,要与外侧的名字对应
CogCaliperTool Ruler = new CogCaliperTool();
Ruler = mToolBlock.Tools["CogCaliperTool1"] as CogCaliperTool ;
//以上两行代码的简写 : CogCaliperTool Ruler = mToolBlock.Tools["CogCaliperTool1"] as CogCaliperTool ;
//myLabel.SetXYText(-60,-25,"文字"+Ruler.Results[0].Width.ToString("F3"))
if (Ruler.Results[0].Width < 1196.24){
myLabel.SetXYText(-60,-25,"NG:"+Ruler.Results[0].Width.ToString("F3")); //x坐标,y坐标,显示文字
}
else
{
myLabel.SetXYText(-60,-25,"PASS:"+Ruler.Results[0].Width.ToString("F3")); //x坐标,y坐标,显示文字
}
// 调整颜色
myLabel.Color = CogColorConstants.Red;
// 调整大小
myLabel.Font = new Font("楷体", 15);
return false;
}
#region When the Current Run Record is Created
/// <summary>
/// Called when the current record may have changed and is being reconstructed
/// </summary>
/// <param name="currentRecord">
/// The new currentRecord is available to be initialized or customized.</param>
public override void ModifyCurrentRunRecord(Cognex.VisionPro.ICogRecord currentRecord)
{
}
#endregion
#region When the Last Run Record is Created
/// <summary>
/// Called when the last run record may have changed and is being reconstructed
/// </summary>
/// <param name="lastRecord">
/// The new last run record is available to be initialized or customized.</param>
public override void ModifyLastRunRecord(Cognex.VisionPro.ICogRecord lastRecord)
{
//3.处写代码,定义输出、把结果放在图像上
// AddGraphicToRunRecord中有四个参数:
// 第一个参数:需要放置的图形mylabel、
// 第二个参数:运行记录 一般都是lastRecord
// 第三个参数:放置的位置、图形信息
// 第四个参数:内容可以为空信息
mToolBlock.AddGraphicToRunRecord(
myLabel,
lastRecord,
"CogFixtureTool1.OutputImage",
" "
);
}
#endregion
#region When the Script is Initialized
/// <summary>
/// Perform any initialization required by your script here
/// </summary>
/// <param name="host">The host tool</param>
public override void Initialize(Cognex.VisionPro.ToolGroup.CogToolGroup host)
{
// DO NOT REMOVE - Call the base class implementation first - DO NOT REMOVE
base.Initialize(host);
// Store a local copy of the script host
this.mToolBlock = ((Cognex.VisionPro.ToolBlock.CogToolBlock)(host));
}
#endregion
}
复制
虽然断断续续接触visionpro,但是收获还是挺大的,技多不压身我真的到现在才开始明白真正的含义
结果展示:
妈妈的吻!加密狗被人拔掉了!!我踏马程序还没保存呢! giao! !!罢了罢了,对着视频整,想要加点自己的程序看看我的代码找点思路