2025.05.28 更新:
上次上传后看到点赞和浏览的人比较多,重新做了一版,后续可以根据需要修改pw ph的值实现在不同的纸上打印坐标纸。只需要计算好纸张的长宽、10个像素对应1mm
很多学生在学习过程中需要使用坐标纸进行绘图,在网上购买坐标纸是主要的做法,但对于羊毛党来说,多花一分钱都是对钱的不尊重
作为一个有担当的社会青年,不能眼瞅着这个造福社会的机会,为大家免费制作了一个使用A4纸打印坐标纸的方法
ps:office中excel无法设置单元格的高或者宽为1mm
思路:既然表格无法实现这个功能,那我直接使用图片搞定
已知:
A4纸的长和宽是210mm和294mm
考虑到需要添加坐标数值,实际操作如下
1、页边距设置上下0.2cm,左右0.5cm-预留存放图片的空间大小为290mm和200mm
注:office中页边距即使设置为0也会有一定的值
2、图像外围预留5mm的空白区域,填写坐标数字,这样A4坐标纸就是上下0.7cm空白左右1cm空白
3、图像像素和mm之间对应关系确认 10像素点<==> 1mm
4、创建像素大小为2900*2000大小的图像
5、只在内部2800*1900区域内画坐标线,cm处5像素红线,0.5cm处3像素红线,0.1mm处画1像素红线
6、生成图片后将图片插入到world中,选中图片,右键-->大小和位置-->设置图像大小为29厘米和20cm。
立即开干!
得到如下图

完整代码如下
clear all;
pw = 2800;ph = 1900;%x短Y长
% pw = 1900;ph = 2800;%X长Y短
pc = 3;
edgew = 50;
plotimg = uint8(zeros(ph,pw,pc));%高度对应矩阵的行
plotimg(:) = 255;
%因为整数厘米数使用5个像素宽度描红,因此向边界扩展2个像素
subimg = plotimg(edgew-2:ph-edgew+2,edgew-2:pw-edgew+2,:);
[subh,subw,~] = size(subimg);
%每行每列的坐标线都画为细红线
halfw = 2;
for i=halfw+1:10:subh
subimg(i,:,:) = 0;
subimg(i,:,1) = 255;
end
for j=halfw+1 :10:subw
subimg(:,j,:) = 0;
subimg(:,j,1) = 255;
end
%5mm线稍微粗一点,占3个像素
for i=halfw + 1:50:subh
subimg(i-1:i+1,:,:) = 0;
subimg(i-1:i+1,:,1) = 255;
end
for j=halfw + 1:50:subw
subimg(:,j-1:j+1,:) = 0;
subimg(:,j-1:j+1,1) = 255;
end
%整数厘米线画5像素粗线
for i=halfw + 1:100:subh
subimg(i-2:i+2,:,:) = 0;
subimg(i-2:i+2,:,1) = 255;
end
for j=halfw + 1:100:subw
subimg(:,j-2:j+2,:) = 0;
subimg(:,j-2:j+2,1) = 255;
end
plotimg(edgew-2:ph-edgew+2,edgew-2:pw-edgew+2,:) = subimg;
fs = 15;
donum = 2;
while(donum>0)
[ph,pw,~] = size(plotimg);%获取图像的行列
%顶部坐标数字区域,要考虑边界上2个像素的粗线
topaxeimg = plotimg(1:edgew-halfw,:,:);
imgwithtext = topaxeimg;
[th,tw,~] = size(imgwithtext);
for ix = edgew: 100: tw
txt = int2str(floor((ix-1)/100));
imgwithtext = insertText(imgwithtext,[ix-fs/2,th-20],txt,'fontsize',fs,'textcolor',[255,0,0],'BoxColor',[255,255,255]);
end
plotimg(1:edgew-halfw,:,:) = imgwithtext;
%底部坐标数字区域,要考虑边界上2个像素的粗线
bottomaxeimg = plotimg(ph-edgew+halfw:ph,:,:);
imgwithtext = bottomaxeimg;
[~,bw,~] = size(imgwithtext);
for ix = edgew: 100: bw
txt = int2str(floor((ix-1)/100));
imgwithtext = insertText(imgwithtext,[ix-fs/2,halfw],txt,'fontsize',fs,'textcolor',[255,0,0],'BoxColor',[255,255,255]);
end
plotimg(ph-edgew+halfw:ph,:,:) = imgwithtext;
%逆时针旋转一下
plotimg = rot90(plotimg);
donum = donum -1;
end
imshow(plotimg);
imwrite(plotimg,'baseAxes.jpg')
294




被折叠的 条评论
为什么被折叠?



