X Plotted Against Y
Basic Usage – pyplot.plot
¶
Surface plot: In this type of graph, a surface is plotted to fit a set of data triplets (X,Y,Z), where Z if obtained by the function to be plotted Z=f (X,Y). Usually, the set of X and Y values are equally spaced. Optionally, the plotted values can be color-coded. Let’s plot price against carat size (i.e., price on the y-axis and carat on the x-axis). Scatter plots are requested in SAS with a SCATTER statment in a PROC SGPLOT. SG stands for “Statistical Graphics”. Click here for the PROC SGPLOT documentation. Click here for the SCATTER statement documentation. Plot against (v. Act in unison or agreement and in secret towards a deceitful or illegal purpose 'The two companies conspired to cause the value of the stock to fall'. An x vector is synthesized as x = 1:length(y), and each column of y is plotted sequentially against this common x axis. Complex Matrix Case - Here the argument data is a complex matrix, in which case, the real part of each column is plotted against the imaginary part of each column. All columns receive the same line styles.
Simple use of matplotlib
is straightforward:
If you run this code in the interactive Python interpreter, you should get a plot like this:
Two things to note from this plot:
pyplot.plot
assumed our single data list to be the y-values;in the absence of an x-values list, [0, 1, 2, 3] was used instead.
Note
pyplot
is commonly used abbreviated asplt
, just asnumpy
is commonlyabbreviated asnp
. The remainder of this chapter uses the abbreviatedform.Note
Enhanced interactive python interpreters such as IPython can automatesome of the plotting calls for you. For instance, you can run
%matplotlib
in IPython, after which you no longer need to runplt.show
everytime when callingplt.plot
.For simplicity,plt.show
will also be left out of the remainderof these examples.
If you pass two lists to plt.plot
you then explicitly set the x values:
Understandably, if you provide two lists their lengths must match:
To plot multiple curves simply call plt.plot
with as many x–y listpairs as needed:
Alternaltively, more plots may be added by repeatedly callingplt.plot
. The following code snippet produces the same plot as theprevious code example:
Adding information to the plot axes is straightforward to do:
Also, adding an legend is rather simple:
And adjusting axis ranges can be done by calling plt.xlim
and plt.ylim
with the lower and higher limits for the respective axes.
In addition to x and y data lists, plt.plot
can also take stringsthat define the plotting style:
The style strings, one per x–y pair, specify color and shape: ‘rx’ standsfor red crosses, and ‘b-.’ stands for blue dash-point line. Check thedocumentationof pyplot.plot
for the list of colors and shapes.
Finally, plt.plot
can also, conveniently, take numpy arrays as its arguments.
The social science of economics makes extensive use of graphs to better illustrate the economic principles and trends it is attempting to explain. Those graphs have specific qualities that are not often found (or are not often found in such combinations) in other sciences.
X Plotted Against Yahoo
A common and specific example is the supply-and-demand graph shown at right. This graph shows supply and demand as opposing curves, and the intersection between those curves determines the equilibrium price. An alteration of either supply or demand is shown by displacing the curve to either the left (a decrease in quantity demanded or supplied) or to the right (an increase in quantity demanded or supplied); this shift results in new equilibrium price and quantity. Economic graphs are presented only in the first quadrant of the Cartesian plane when the variables conceptually can only take on non-negative values (such as the quantity of a product that is produced). Even though the axes refer to numerical variables, specific values are often not introduced if a conceptual point is being made that would apply to any numerical examples.
More generally, there is usually some mathematical model underlying any given economic graph. For instance, the commonly used supply-and-demand graph has its underpinnings in general price theory—a highly mathematical discipline.
X Plotted Against Yellow
Choice of axes for dependent and independent variables[edit]
In most mathematical contexts, the independent variable is placed on the horizontal axis and the dependent variable on the vertical axis. For example, if f(x) is plotted against x, conventionally x is plotted horizontally and the value of the function is plotted vertically. This placement is often, but not always, reversed in economic graphs. For example, in the supply-demand graph at the top of this page, the independent variable (price) is plotted on the vertical axis, and the dependent variable (quantity supplied or demanded), whose value depends on price, is plotted horizontally.
However, when time is the independent variable, and values of some other variable are plotted as a function of time, normally the independent variable time is plotted horizontally, as in the line graph to the right.
Yet other graphs may have one curve for which the independent variable is plotted horizontally and another curve for which the independent variable is plotted vertically. For example, in the IS-LM graph shown here, the IS curve shows the amount of the dependent variable spending (Y) as a function of the independent variable the interest rate (i), while the LM curve shows the value of the dependent variable, the interest rate, that equilibrates the money market as a function of the independent variable income (which equals expenditure on an economy-wide basis in equilibrium). Since the two different markets (the goods market and the money market) take as given different independent variables and determine by their functioning different dependent variables, necessarily one curve has its independent variable plotted horizontally and the other vertically.