问题描述
我在gnuplot中有这张图:
I have this graph in gnuplot:
我想包括三个彩色折线图的每一个的总计.一种可能性是用以下方式替换密钥:
I want to include totals for each of the three colored line graphs. One possibility is to replace the key with this:
我可以使用可以切换颜色的单个标签进行绘制吗?如果没有,那么我将不得不使用六个标签.在那种情况下,鉴于字符串的宽度可以变化,如何确定标签的坐标?我可以使用固定宽度的字体,并根据每个总数中的位数进行一些计算,但这似乎很乏味.
Can I plot this with a single label that switches colors? If not then I'd have to use six labels. In that case, how do I determine the coordinates of the labels given that the widths of the strings can vary? I could use a fixed width font and do some computation based on the number of digits in each of the totals but this seems tedious.
还有一种更聪明的方法来表示图中的总数吗?
Is there a more clever way to indicate totals in a graph?
推荐答案
您不能在单个标签内更改文本颜色,必须使用六个不同的标签.但是,有一些方法可以简化此过程:
You cannot change the textcolor inside a single label, you must use six different labels. However, there are some ways to simplify this:
-
在x方向上对彩色标签使用
left
和负offset
,对数字使用right
和正offset
作为
Use
left
and a negativeoffset
in x-direction for the colored label, andright
and a positiveoffset
for the number, like
set label 1 right at graph 0.5, char 1 "FY2013" tc lt 1 offset char -0.5,0
set label 2 left at graph 0.5, char 1 "34,674" offset char 0.5,0
使用set macros
并定义一个字符串变量anchor="graph 0.5, char 1"
,该变量用于设置所有标签的锚点.
Use set macros
and define a string variable anchor="graph 0.5, char 1"
which you use to set the anchor point of all labels.
set macros
anchor="graph 0.5, char 1"
set label 1 at @anchor "FY2013" tc lt 1 offset char -0.5,0
将所有标签移动到单个锚点附近,并使用两个变量来参数化此点的偏移量:
Shift all labels around a single anchor point, and parametrize the offsets from this point using two variables:
set macros
anchor="graph 0.5, char 1"
ofs_x = 0.5
dx = 20
set label 1 right at @anchor "FY2013" tc lt 1 offset char -dx - ofs_x,0
set label 2 left at @anchor "34,674" offset char -dx + ofs_x,0
set label 3 right at @anchor "FY2014" tc lt 2 offset char -ofs_x,0
set label 4 left at @anchor "16,240" offset char ofs_x,0
set label 5 right at @anchor "FY2015" tc lt 3 offset char dx - ofs_x,0
set label 6 left at @anchor "6,863" offset char dx + ofs_x,0
set bmargin 3.5
plot -x
那仍然不是一个全自动的解决方案,但是归结为仅为anchor
和dy
选择适当的值.
That still isn't a fully automatic solution, but boils down to choosing appropriate values for the anchor
and dy
only.
这篇关于gnuplot标签中可以有多种颜色吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!