How to create/print graph labels form a list of values in plot2d()? - plot

The issue
Assume the explicit solution to a differential equation to be:
(%i1) x(t):=((x[0]*%e^(k*t))/(x[0]*%e^(k*t)-x[0]+1))
Obviously the parameter k affects the slope of the solutions, as can be seen by graphing them together for different values of k (in this example, varying from k=0.25 to k=1.75 with step 0.25).
Trying to plot the graphs this way
(%i6) plot2d(
makelist(subst([k=d*0.25,x[0]=0.1],x(t)), d,1,7),
[t,0,15],
cons(legend, makelist("k=d*0.25", d,1,7)),
[gnuplot_preamble,"set key right bottom"]
)$
however yields a plot with "static" labels for each solution:
Next we returned to a solution offered here on stackoverflow (maxima-plotting-in-a-loop) and adapted it to this case:
(%i7) makelist(subst([k=d*0.25,x[0]=0.1],x(t)), d,1,7);
plot2d(%, [t,0,15],
[gnuplot_preamble,"set key nobox spacing 1.1 bottom right"]
)$
This is an improvement over the first attempt, but this code prints the entire function names x(t)=(x_0*e^(k*t))/(x_0*e^(k*t)-x_0+1) with k=d×0.25,d=1,…,7 as legend labels and thus it is not very reader-friendly.
What we actually want to have in the legend are just the k-values from this list:
(%i8) kV: makelist(k=d*0.25, d,1,7);
(%o8) [k=0.25,k=0.5,k=0.75,k=1.0,k=1.25,k=1.5,k=1.75]
So we tried this to get the following error message:
(%i11) plot2d(
makelist(subst([k=d*0.25,x[0]=0.1],x(t)), d,1,7),
[t,0,15],
cons(legend, makelist(kV)),
[gnuplot_preamble,"set key right bottom"]
)$
Value of option legend. should be a string or false, not "
[k = 0.25,k = 0.5,k = 0.75,k = 1.0,k = 1.25,k = 1.5,k = 1.75]
".
-- an error. To debug this try: debugmode(true);
Does anyone know how to get these k values into the legend?
Any help/suggestions appreciated.
Cheers, Tilda
The issue solved
Robert's suggestion helped. So
plot2d(
makelist(
subst([k=d*0.25,x[0]=0.1],x(t)), d,1,7),
[t,0,15],
cons(legend, map(string, kV)),
[gnuplot_preamble,"set key right bottom"]
)$
yields the correct plot now:
Thanks to Raymond's answer and his clarifications on the intricacies of Maxima's printf(), we now have the icing on the cake:
plot2d(
makelist(subst([k=d*0.25,x[0]=0.1],x(t)), d,1,7),
[t,0,15],
cons(legend, makelist(printf(false,"k = ~,2f", 0.25*d), d,1,7)),
[gnuplot_preamble, "set key nobox spacing 1.1 right bottom"]
)$
A workaround to typesetting titles in a typographically correct way is to use captions, as can be seen from a screenshot of a TeXmacs session. This is not really the jewel to the crown, but pretty close.

An alternative:
plot2d(
makelist(subst([k=d*0.25,x[0]=0.1],x(t)), d,1,7),
[t,0,15],
cons(legend, makelist(printf(false, "k=~2f", 0.25*d), d,1,7)),
[gnuplot_preamble,"set key right bottom"]
);
This is kind of nice because then all the legends line up nicely.

Related

Coldfusion: CFChart format labels on horizontal bar graph

I am having trouble aligning Horizontal Bar graph x-axis Labels, I have long names that I have wrapped using /n. The labels are no longer right aligned (see picture). Is there a way to left or right align (see image)?
I am new creating charts in CF and am stumbling around, if anyone can point me to any documentation that will allow me to know what are valid attributes are for elemets (ie: xAxis...itemsOverlap), I stumbled on this from a post but don't know where to find this info, thanks.
While I am here is there any way to change the color of the value displayed for each bar? (or have that number appear inside the bar?).
again thank for your patients as I am new to this.
<CFSET xAxis_disp = {"itemsOverlap":true, "max-items": SQL_Query.RecordCount}>
<CFSET aspect3d_small={"angle":0,"depth":7,"true3d":false}>`
<CFSET yAxisStep_25 = {"min-value":"0","step":"5"}>
<CFCHART
style="default"
show3d="yes"
chartHeight="#chartHeight_error#"
chartwidth="500"
type="horizontalbar"
gridlines="20"
yAxis = "#yAxisStep_25#"
xAxis="#xAxis_disp#"
aspect3d="#aspect3d_small#"
font="times" >
<CFCHARTSERIES
colorlist="##234086,##284A99,##284A99,##325CC0,##3D68CD,##5077D2,##6486D7,##7795DC,##8BA4E1"
query="SQL_Query"
type="bar"
datalabelstyle="value"
itemcolumn="CRFNAME"
valuecolumn="ErrCounter">
</CFCHARTSERIES>
</CFCHART>
Chart Labels, not aligned
FWIW, CFChart is just a wrapper around ZingChart, so the ZingCharts docs will be more helpful for stuff like this. I usually end up googling "How to do [X] with ZingChart" and/or pore over the ZingChart docs to find the syntax ... then figure out how it maps to the CF attributes with a little trial and error :-).
Anyway, the xAxis item alignment is controlled with "item": { "text-align":"right"}. Add it to your xAxis_disp structure. For the other xAxis attributes (i.e. "Scale-X"), have a look at the ZingChart docs
<CFSET xAxis_disp = {"items-overlap":true
, "max-items": 6
, "auto-fit": true
, "item": { "text-align":"right"}
}>
Runnable TryCF.com Example

tradingview pine script error "cannot use 'plot' in a local scope"

I am trying to write a simple if-then-else statement using the Pine language under Tradingview. What the code does is based upon user input.
If the box is checked, the plot the line.
If the box is not checked do not plot the line.
This is the code I have:
notPlot = -2000
var ch382= input(true, ".382")
if ch382
plot( ch382? bottom + diff * .382: noPlot, title="fib-.236", linewidth=3, color=color.orange )
How can I write this in a proper way?
If I try to run it, I get: “cannot use 'plot' in a local scope”
Any assistance would be greatly appreciated.
ETA: I found this thread below
How to put plot statement inside if statement
but -
what I need to do is to plot if the box is checked and ~not plot~ if the box is not checked.
ETA: figured out the issue. One would use "na" (in the case of plotting) to note that the line should not be displayed - my mistake ...
var ch382 = input(true, ".382")
plot( ch382? bottom + diff * .382: na, title="fib-.382", linewidth=3, color=color.orange )

Logarithmic x and y axis for image plot

I need to do this in a different way, since pcolor produces diagonal lines in the output file
h=pcolor(rand(16)); %The actual data comes from hist3
set(h,'EdgeColor','none');
colormap(gray(256));
set(gca,'yscale','log');
set(gca,'xscale','log');
print('test.png','-dpng','-r4800'); %Gives diagonal lines in text.png
Is there a simple workaround the bug. I use the FLTK backend.
Update
Switching to gnuplot removes the diagonal lines, but adds vertical and horizontal lines, but changes increases the plot margins too much.
Here is a "solution" to the bug. The idea is to disable anti-aliasing for graphics.
gswrapper.sh
#!/bin/bash
ARGS=()
ARGS+=("-dGraphicsAlphaBits=1")
for var in "$#"; do
[ "$var" != '-dGraphicsAlphaBits=4' ] && ARGS+=("$var")
done
gs "${ARGS[#]}"
Octave script:
h=pcolor(rand(16)); %The actual data comes from hist3
set(h,'EdgeColor','none');
colormap(gray(256));
set(gca,'yscale','log');
set(gca,'xscale','log');
print('test.png','-dpng','-r600','-G./gswrapper.sh');

Syntax Error in Octave plotting

I got the following syntax error while I want to plot values:
syntax error
>>> plot(freq1, abs(fft1/max(fft1)),xlabel('f(Hz)'), ylabel('Amplitude I(f)');
^
My definitions are as follows:
a=x+y+z; % a is a sinus mixture of different curves/functions
n1 = fa/0.05; % N is 50 ms
fft1=fft(a,n1);
freq1 = [0:deltaF1:fa-fft1];
plot(freq1, abs(fft1/max(fft1)),xlabel('f(Hz)'), ylabel('Amplitude I(f)');
EDIT: It would be nice stop voting me down, I know that question is not too interesting (please see below in the comment to the answer), thank you!
You have more opening brackets ( than closing ones ), that's a syntax error.
It should be:
plot(freq1, abs(fft1/max(fft1)),xlabel('f(Hz)'), ylabel('Amplitude I(f)'));

matplotlib mathtext does not work

I'm doing a hist plot and I want some numbers shown in the plot, so I put in a text box using mathtext for the text, but I doesn't work and I can't see why.
a = [2086., 360.5, 1000.]
b = [977., 37., 498.]
c = [4512., 690., 378.]
textstr = r'$\per50=%.2f$\n$\per16=%.2f$\n$\per84=%.2f$'%(a[0],b[0],c[0])
# these are matplotlib.patch.Patch properties
props = dict(boxstyle='round', facecolor='wheat', alpha=0.75)
# place a text box in upper left in axes coords
ax.text(0.05, 0.95, textstr, transform=ax.transAxes, fontsize=14,
verticalalignment='top', bbox=props)
At the end of my figure I'm getting this error:
matplotlib.pyparsing.ParseFatalException: Expected end of math '$'
$\per50=2086.00$\n$\per16=977.00$\n$\per84=4512.00$ (at char 0), (line:1, col:1)
I hope you can help me!
You are getting that error because the command $\per$ does not exist. Is that a latex command you defined? If you set the matplotlib parameter text.usetex=True, it is possible to set a latex preamble and define commands there, e.g.:
rc('text', usetex=True)
rc('text.latex', preamble='something')
But I don't think this can be used to define new commands (and the use of preamble is discouraged). So your best bet is to write explicitly in matplotlib whatever \per stands for.

Resources