I very often plot two types of results - e.g. prediction vs measurement - into a figure for a document, where the look of the corresponding lines/scatters should be match each other in different plots, but at the beginning of the writing/plotting the final look is not decided. I would like to define a bunch of plot options for every such curve, to make it possible to replot them very efficiently.
For example a would like to define the styles like:
s_theory = [linestyle="--", color="grey", marker=None, label="simulation"]
s_measurement = [linestyle=":", color="black", marker="s", markersize="5",label="measurement"]
I would like to apply these magically on plt.plot():
plt.plot(xt,yt,**s_theory)
plt.plot(xm,ym,**s_measurement)
How can I do that? What is the magic word I did not found during my search for this task? I am pretty sure there is a very simple to do that.
Based on the comment of ImportanceOfBeingErnest:
style_sim = {"linestyle":"--", "color":"grey", "marker":"None", "label":"simulation"}
style_meas = {"linestyle":":", "color":"black", "marker":"s", "markersize":5, "label":"measurement"}
plt.plot(xt,yt,**style_sim)
plt.plot(xm,ym,**style_meas)
If you find it useful, please vote up the comment of ImportanceOfBeingErnest!
Related
R beginner here so sorry for the basic question... I have worked in class to draw some boxplots using the boxplot() function. As part of the assignment I've been asked to add data points to the boxplots. I can't seem to find an argument in the boxplot() function to do this...Is there another function I need to use? Thank you!
I recommend looking into ggplot2 package within R.
You can create multiple visualizations, including a boxplot with the data points shown. This is the ggplot code to do so:
library(ggplot2)
ggplot(df, aes(x=catvar, y=yvar)) +
geom_boxplot()+geom_dotplot(binaxis='y', stackdir='center', dotsize=1)
My code is the following, I would like a to assume iteratives values like '3' , '4' and so on. My code is like:
a=2
#perform some basic operation like:
b=a*2
#convert it to string
c=str(b)
p path1 u 1:($1<=0?$#c:1/0) w filledcurves y=0
The solution proposed on similar topic here so far did not work.
You should use this syntax
c=''.b
c will be equal to 'b'
gnuplot provides both sprintf (as in the C language routine) and a private implementation gprintf that offers formatting options beyond the normal ones provided by the C language. The full details with all supported format options are in the gnuplot documentation. A very simple use would be:
c = sprintf("%8.3f", b)
However, it makes no sense to convert the value to a string if your intent is to use it in a plot command that expects a number. There is no iteration in the pseudo-code you show so I can't guess exactly where you are headed with this but note that the operation #c to evaluate c as a macro expansion inside an iteration will always yield the content of c as it was prior to the iteration. So using the # operator inside an iteration is almost always wrong.
If I correctly understand your minimal incomplete non-working example, I can only guess what you probably wanted to do, i.e. limit the plot of a dataset in a certain column which is selected by some variable. Correct? If my guess is true, I would do it the following way, no need for string conversion and the use of macros. Check help column.
a=2
# perform some basic operation like:
b=a*2
plot path1 u 1:($1<=0 ? column(b) : NaN) w filledcurves y=0
I need to interpret an SVG input data and identify the displayed points.
In the SVG format, any point may be part of a group ( element ) to which transformations (translate/rotate/scale) may be applied. For every point, I need to bubble up and apply transformation of every ancestor, in order to find the position that the point has in the rendering. After reading some web pages on the subject (and trying to remember from school), I understand that the usual way to do this in .NET is to use 3x3 mathematical matrices, so I try to figure out the System.Windows.Media.Matrix class.
It's been a while since I took Math, and I can't recall this one particular detail.
I typed up the following code in LINQPad:
var matrix = new Matrix(1,1,1,6,0,0);
var matrix2 = new Matrix(2,1,0,6,0,0);
var matrix3 = new Matrix(0,1,2,6,0,0);
var pts = new[]{
new System.Windows.Point(0,0),
new System.Windows.Point(1,1),
new System.Windows.Point(2,2),
new System.Windows.Point(3,3),
new System.Windows.Point(4,4),
new System.Windows.Point(5,5)
}.ToArray();
pts.Select(org=>new{org,changed=matrix.Transform(org),changed2=matrix2.Transform(org),changed3=matrix3.Transform(org)}).Dump("Transformation Samples");
... and trying out different values in the Matrix constructor.
However it seems that these values have no impact on the final result.
new Matrix(1,1,1,6,0,0);
new Matrix(2,1,0,6,0,0);
new Matrix(0,1,2,6,0,0);
(same is true for arguments 2 and 4)
The only thing that seems to matter is the sum of the two (which in this case is 2). I assume that this is due to my limited input data and that given other input data, some difference could be seen that would make sense in some visual tranformation.
Can anybody help me out here?
Perhaps the section in the SVG spec about how transform matrixes work will be of use to you?
http://www.w3.org/TR/SVG/coords.html#TransformMatrixDefined
I am trying to create a histogram of numbers in an array. I am using Matlab to do this. I am connecting via ssh so I can only use Matlab in the terminal on my Linux computer. I am trying to create a histogram of the data in the array and save it as a .png. I know that in order for me to save this I need to use the print function. So far my attempt has been the following:
h=hist(array)
print(h,'-dpng','hist1.png')
which told me that there is no variable defined as -dpng but I thought that the point of that was to specify the file type.
Then I just deleted the -dpng and ran it as
print(h,'hist1.png')
to which it told me "Handle must be scalar, vector, or cell-array of vectors"
At this point I don't quite know what to do next. I would like for someone to help me figure out how to print this histogram to a .png file. Thank you.
hist does not return a figure handle, you could to do something similar to:
h = figure;
hist(array);
print(h, '-dpng', 'hist1.png');
to save the histogram.
By itself, the function hist(array) plots a histogram. If you assign the output to a variable, it returns the binned values of array, not the handle to your plot.
f = figure;
hist(array)
saveas(f,'hist.png')
you may would like to output the array to a csv file.
fid = fopen('file.csv','wt');
for i=1:size(arr)
fprintf(fid, '%s,%d,%d\n','element number' ,i ,arr(i));
end
fclose(fid);
See this link, you should be able to change the answers there to your needs: Outputing cell array to CSV file ( MATLAB )
You don't need to use figure handle unless you want to print not current figure. By default print uses gcf that returns handle for current figure.
So you just can do:
hist(array)
print('-dpng','hist1.png')
You got an error that there is no variable defined as -dpng probably because you forgot one quote symbol and used -dpng'.
I have a LaTeX document where I'd like the numbering of floats (tables and figures) to be in one numeric sequence from 1 to x rather than two sequences according to their type. I'm not using lists of figures or tables either and do not need to.
My documentclass is report and typically my floats have captions like this:
\caption{Breakdown of visualisations created.}
\label{tab:Visualisation_By_Types}
A quick way to do it is to put \addtocounter{table}{1} after each figure, and \addtocounter{figure}{1} after each table.
It's not pretty, and on a longer document you'd probably want to either include that in your style sheet or template, or go with cristobalito's solution of linking the counters.
The differences between the figure and table environments are very minor -- little more than them using different counters, and being maintained in separate sequences.
That is, there's nothing stopping you putting your {tabular} environments in a {figure}, or your graphics in a {table}, which would mean that they'd end up in the same sequence. The problem with this case (as Joseph Wright notes) is that you'd have to adjust the \caption, so that doesn't work perfectly.
Try the following, in the preamble:
\makeatletter
\newcounter{unisequence}
\def\ucaption{%
\ifx\#captype\#undefined
\#latex#error{\noexpand\ucaption outside float}\#ehd
\expandafter\#gobble
\else
\refstepcounter{unisequence}% <-- the only change from default \caption
\expandafter\#firstofone
\fi
{\#dblarg{\#caption\#captype}}%
}
\def\thetable{\#arabic\c#unisequence}
\def\thefigure{\#arabic\c#unisequence}
\makeatother
Then use \ucaption in your tables and figures, instead of \caption (change the name ad lib). If you want to use this same sequence in other environments (say, listings?), then define \the<foo> the same way.
My earlier attempt at this is in fact completely broken, as the OP spotted: the getting-the-lof-wrong is, instead of being trivial and only fiddly to fix, absolutely fundamental (ho, hum).
(For the afficionados, it comes about because \advance commands are processed in TeX's gut, but the content of the .lof, .lot, and .aux files is fixed in TeX's mouth, at expansion time, thus what was written to the files was whatever random value \#tempcnta had at the point \caption was called, ignoring the \advance calculations, which were then dutifully written to the file, and then ignored. Doh: how long have I know this but never internalised it!?)
Dutiful retention of earlier attempt (on the grounds that it may be instructively wrong):
No problem: try putting the following in the preamble:
\makeatletter
\def\tableandfigurenum{\#tempcnta=0
\advance\#tempcnta\c#figure
\advance\#tempcnta\c#table
\#arabic\#tempcnta}
\let\thetable\tableandfigurenum
\let\thefigure\tableandfigurenum
\makeatother
...and then use the {table} and {figure} environments as normal. The captions will have the correct 'Table/Figure' text, but they'll share a single numbering sequence.
Note that this example gets the numbers wrong in the listoffigures/listoftables, but (a) you say you don't care about that, (b) it's fixable, though probably mildly fiddly, and (c) life is hard!
I can't remember the syntax, but you're essentially looking for counters. Have a look here, under the custom floats section. Assign the counters for both tables and figures to the same thing and it should work.
I'd just use one type of float (let's say 'figure'), then use the caption package to remove the automatically added "Figure" text from the caption and deal with it by hand.