Insert text in a specific location of a graph

馋奶兔 提交于 2019-12-11 08:03:27

问题


I have two functions y=5*x+3 and y=8*x+2.

After i type the command:

graph twoway (function y=5*x+3) (function y=8*x+2)

I can use the graphics editor to write text near the intersection of the two lines.

However, I would not like to do this all the time.

Is there a way to create the graph with the text without adding it later?


回答1:


There is a text option for the graph twoway command that does this.

First, you obviously need to solve for x and then get the value of y:

5x + 3 = 8x + 2
x = (-3 + 2) / -3
x = 0.333

y = 8 * 0.333 + 2
y = 4.664

With both coordinates at hand, you just need to add the textbox in your twoway command:

twoway (function y=5*x+3) (function y=8*x+2), text(4.664 0.333 "Intersection", placement(11))

See added text options in the Stata manual for more details.


EDIT:

Alternatively, you could also use a marker:

twoway (function y=5*x+3) (function y=8*x+2) (scatteri 4.664 0.333 (11) "Intersection")

The entry on graph twoway scatteri in the Stata manual provides additional information.



来源:https://stackoverflow.com/questions/51987747/insert-text-in-a-specific-location-of-a-graph

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!