Hot answers tagged

10

#!/usr/bin/env python import numpy as np import matplotlib.pyplot as plt def fun (n, x): if n <= x <= n + 1: return float(x) - n elif n + 1 <= x <= n + 2: return 2.0 - x + n return 0.0 vfun = np.vectorize(fun) x = np.linspace(0, 10, 1000) y = vfun(3, x) plt.plot(x, y, '-') plt.show()


5

You could either fit a logistic function (possibly composing it with a linear function), use segmented regression, or classification and regression trees, among other options. The original data, shown in the figure below, was fitted in Gnuplot using the following commands: h(x) = k * 0.5 * (1.0 - tanh(0.5 * (a * x + b))) + c * x + d fit h(x) 'plot-EV.txt' ...


5

You can't just use TeX syntax unless you are using the TiKZ, epslatex, or another terminal that uses LaTeX to process the labels. You can get some fairly crude math layout, including superscripts and subscripts, by using the enhanced text option to many of gnuplot's terminals, including, sometimes, png. But you will have to use the gnuplot enhanced text ...


5

GNUplot has the ability to have 2 x- and 2 y-axes per plot. The additional axes are called x2 and y2. according to GNUplot.info FAQ Here is a demo of it being used. Also have a read of help plot from within the GNUplot program.


3

An assortment of curves for fitting chemistry examples is presented in these Colby College class notes. Of particular application is the sigmoid response curve with variable "slope" for the central part of the curve: $$ f(x) = \frac{a}{1 + e^{bx - c} } + d $$ [This is similar to the suggested logistic function proposed in the first Answer, but has four ...


3

Another option would be to use the matplotlib package in Python. You can create a function f(n, x) that evaluates the function rather easily, and then evaluate it for a set of points. The resulting plot commands are very MATLAB-like, so if you know MATLAB, the work in matplotlib will be quite easy. If you're a student, you can get a free, easy-to-install ...


3

If you just want to visualize your data, you may try exporting it in a text file to visualize it with gnuplot. For your simple example, you may try to plot it in gnuplot directly as in this example. In Matlab/Octave, if you have your function as pairs of data x1/y1 and x2/y2, you can plot them using plot( x1 , y1 , x2 , y2 ).


3

It is possible to use LaTeX syntax for super- and subscripts in axes labels and titles when the terminal is set to png. To to this, set the terminal with set term png enhanced font "/full/path/to/font" and then plot normally. If the font part isn't included, you may get this error message: gdImageStringFT: Could not find/open font This means gnuplot ...


2

SymPy should be able to represent and plot your piecewise function relatively well: from sympy import * x = Symbol('x') n = 2 # You'll have to choose some explicit number for n f = Piecewise((0, n<=x), (x-n, x<=n+1), (2-x+n, x<=n+1), (0, True)) Plot(f)


1

Thanks to Thor, I figured out the solutions to my questions. As he pointed out, the range of the function can be specified in the fit command. In the above data set, the linear region starts from x=2.63. set term svg set output 'blue.svg' set term svg set output 'blue.svg' f(x) = a*x + b fit[2.63:] f(x) '07-B.txt' via a,b plot[][-1:3] '07-B.txt' pt 7, f(...


Only top voted, non community-wiki answers of a minimum length are eligible