楼主: ChrisEdward
4139 5

[作图问题求助] 请问三次项的作图该怎么进行呢????重谢! [推广有奖]

  • 1关注
  • 7粉丝

已卖:3680份资源

副教授

22%

还不是VIP/贵宾

-

威望
0
论坛币
332543 个
通用积分
18.2515
学术水平
22 点
热心指数
12 点
信用等级
13 点
经验
15410 点
帖子
278
精华
1
在线时间
986 小时
注册时间
2011-9-5
最后登录
2025-9-15

楼主
ChrisEdward 发表于 2015-7-25 19:36:16 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
假如方程为y=x+x^2+x^3,那么这个图该怎么用stata画呢,我看好多都是二次项的拟合,但是这样的函数该怎么画出来呢~~~
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Stata tata

沙发
ywh19860616 发表于 2015-7-25 20:03:45
http://www.fight-entropy.com/2013/01/plot-polynomial-of-any-degree-in-stata.html

藤椅
蓝色 发表于 2015-7-25 20:54:11
twoway function y=x+x^2+x^3, range(-50 50)
Graph.png

stata的manual和作图的书上都讲了。
可惜就是不看
这样自己是学不会stata



Title

    [G-2] graph twoway function -- Twoway line plot of function


Syntax

        twoway function [[y]=] f(x) [if] [in] [, options]

    options               Description
    --------------------------------------------------------------------------------------------
    range(# #)            plot over x = # to #
    range(varname)        plot over x = min to max of varname
    n(#)                  evaluate at # points; default is 300

    droplines(numlist)    draw lines to axis at specified x values
    base(#)               base value for dropline(); default is 0

    horizontal            draw plot horizontally

    yvarformat(%fmt)      display format for y
    xvarformat(%fmt)      display format for x

    cline_options         change look of plotted line

    axis_choice_options   associate plot with alternative axis

    twoway_options        titles, legends, axes, added lines and text, by, regions, name, aspect
                            ratio, etc.
    --------------------------------------------------------------------------------------------
    All explicit options are rightmost, except horizontal, which is unique; see repeated
      options.
    if exp and in range play no role unless option range(varname) is specified.
    In the above syntax diagram, f(x) stands for an expression in terms of x.


Menu

    Graphics > Twoway graph (scatter, line, etc.)


Description

    twoway function plots y = f(x), where f(x) is some function of x.  That is, you type

        . twoway function y=sqrt(x)

    It makes no difference whether y and x are variables in your data.


Options

    range(# #) and range(varname) specify the range of values for x.  In the first syntax,
        range() is a pair of numbers identifying the minimum and maximum.  In the second syntax,
        range() is a variable name, and the range used will be obtained from the minimum and
        maximum values of the variable.  If range() is not specified, range(0 1) is assumed.

    n(#) specifies the number of points at which f(x) is to be evaluated.  The default is
        n(300).

    droplines(numlist) adds dropped lines from the function down to, or up to, the axis (or
        y=base() if base() is specified) at each x value specified in numlist.

    base(#) specifies the base for the droplines().  The default is base(0).  This option does
        not affect the range of the axes, so you may also want to specify the axis_scale_option
        yscale(range(#)) as well; see [G-3] axis_scale_options.

    horizontal specifies that the roles of y and x be interchanged and that the graph be plotted
        horizontally rather than vertically (that the plotted function be reflected along the
        identity line).

    yvarformat(%fmt) and xvarformat(%fmt) specify the display format to be used for y and x.
        These formats are used when labeling the axes; see [G-3] axis_label_options.

    cline_options specify how the function line is rendered; see [G-3] cline_options.

    axis_choice_options associate the plot with a particular y or x axis on the graph; see [G-3]
        axis_choice_options.

    twoway_options are a set of common options supported by all twoway graphs.  These options
        allow you to title graphs, name graphs, control axes and legends, add lines and text,
        set aspect ratios, create graphs over by() groups, and change some advanced settings.
        See [G-3] twoway_options.


Remarks

    Remarks are presented under the following headings:

        Typical use
        Advanced use 1
        Advanced use 2


Typical use

    You wish to plot the function y=exp(-x/6)sin(x) over the range 0 to 4pi:

        . twoway function y=exp(-x/6)*sin(x), range(0 12.57)
          (click to run)

    A better rendition of the graph above is

        . twoway function y=exp(-x/6)*sin(x), range(0 12.57)
                yline(0, lstyle(foreground))
                xlabel( 0
                        3.14 "{&pi}"
                        6.28 "2{&pi}"
                        9.42 "3{&pi}"
                       12.57 "4{&pi}")
                plotregion(style(none))
                xsca(noline)
          (click to run)

    yline(0, lstyle(foreground)) added a line at y=0; lstyle(foreground) gave the line the same
    style as used for the axes.  See [G-3] added_line_options.

    xlabel(0 3.14 "{&pi}" 6.28 "2{&pi}" 9.42 "3{&pi}" 12.57 "4{&pi}") labeled the x axis with
    the numeric values given and substituted text for the numeric values; see [G-3]
    axis_label_options.

    plotregion(style(none)) suppressed the border around the plot region; see [G-3]
    region_options.

    xsca(noline) suppressed the drawing of the x-axis line; see [G-3] axis_scale_options.


Advanced use 1

    The following graph appears in many introductory textbooks:

        . twoway
              function y=normalden(x), range(-4 -1.96) color(gs12) recast(area)
          ||  function y=normalden(x), range(1.96 4)   color(gs12) recast(area)
          ||  function y=normalden(x), range(-4 4) lstyle(foreground)
          ||,
              plotregion(style(none))
              ysca(off) xsca(noline)
              legend(off)
              xlabel(-4 "-4 sd" -3 "-3 sd" -2 "-2 sd" -1 "-1 sd" 0 "mean"
                      1  "1 sd"  2  "2 sd"  3  "3 sd"  4  "4 sd"
                      , grid gmin gmax)
              xtitle("")
          (click to run)

    We drew the graph in three parts:  the shaded area on the left, the shaded area on the
    right, and then the overall function.  To obtain the shaded areas, we used the
    advanced_option recast(area) so that, rather than the function being plotted by graph twoway
    line, it was plotted by graph twoway area; see [G-3] advanced_options and [G-2] graph twoway
    area.  Concerning the overall function, we drew it last so that its darker
    foreground-colored line would not get covered up by the shaded areas.


Advanced use 2

    function plots may be overlaid with other twoway plots.  For instance, function is one way
    to add y=x lines to a plot:

        . sysuse sp500, clear

        . scatter open close, msize(*.25) mcolor(*.6) ||
          function y=x, range(close) yvarlab("y=x") clwidth(*1.5)
          (click to run)

    In the above, we specified the advanced_option yvarlab("y=x") so that the variable label of
    y would be treated as "y=x" in the construction of the legend; see [G-3] advanced_options.
    We specified msize(*.25) to make the marker symbols smaller, and we specified mcolor(*.6) to
    make them dimmer; see [G-4] relativesize and [G-4] colorstyle.




已有 2 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
nuomin + 100 + 100 + 5 + 5 + 5 热心帮助其他会员
hustchen2012 + 10 + 40 + 1 + 1 + 1 精彩帖子

总评分: 经验 + 110  论坛币 + 140  学术水平 + 6  热心指数 + 6  信用等级 + 6   查看全部评分

板凳
ChrisEdward 发表于 2015-7-26 04:54:30
蓝色 发表于 2015-7-25 20:54
twoway function y=x+x^2+x^3, range(-50 50)
非常感谢!

报纸
ChrisEdward 发表于 2015-7-26 04:55:06
ywh19860616 发表于 2015-7-25 20:03
http://www.fight-entropy.com/2013/01/plot-polynomial-of-any-degree-in-stata.html
非常感谢!!

地板
tmdxyz 发表于 2015-7-26 04:57:00
我也没看见楼主说的重谢是怎么兑现的,呵呵

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-22 16:15