problem with using statement in gnuplot - using

I'm trying to plot some data. I have a file looking like this
50 11 1 1
100 29 1 6
200 62 4 26
300 104 9 39
and a plotfile
# Vergleich
set terminal png
set output "streetsegments.png"
set datafile separator "\t"
set yrange [0:105]
set ytics ("0" 0, "10" 10, "20" 20, "30" 30, "40" 40, "50" 50, "75" 75, "100" 100)
set xtics ("50" 50, "100" 100, "200" 200,"300" 300)
set xrange [0:300]
set xlabel "Error in meters"
set ylabel "Street segments"
set notitle
plot "segments" using 1:2 t 'foo' with lp, \
"segments" u 1:3 t 'bar' with lp, \
"segments" u 1:4 t 'baz' with lp
But when plotting, it doesn't show anything besides the titles of the lines, but no lines themselves are drawn. Any idea, why this doesn't work?
When only plotting on column (by not using the "using"-statement ) it works just fine.

Works for me. Try again removing the set datafile separator "\t" line and see if that solves it.

Related

Histogram of a value for a variable over unique values of another variable

I have a dataset in Stata with 203 rows and 2 columns. Here is some rows:
Voting Bidvalue
0 720
1 15
0 120
0 960
1 30
1 400
0 60
0 960
0 240
There are eight different bid values including 15, 30, 60, 120, 240, 360, 480, 720. For each bid value, we can find the number of 1 and 0 for the Voting column. Here is the screenshot of the detailed information.
I want to find a histogram that the x-axis is 8 bid values and the y-axis is the number of 1 for the Voting column.
histogram Bidvalue if Voting == 1 , freq
is an answer to the question. It is perhaps more likely that you want something more like
egen Toshow = group(Bidvalue), label
label var Toshow "Bidvalue"
histogram Toshow if Voting == 1, xla(1/8, valuelabel) discrete freq
The following works for me:
graph bar (count) Voting, over(Bidvalue)

Julia plotting issues: label overlap and LaTeXStings expansion

I am having two mutually exclusive issues with my sample plot below.
The y-axis label and y-tick labels are on top of each other. I have
not been able to find a way to shift either. I would like
the size of the plot to expand to accommodate the necessary spacing.
I want the y-axis label to be sigma with a subscript theta. It looks like Unicode does not allow a subscript theta. I was hoping to get around this limitation by using LaTeXStrings. However, I cannot get the LatexString to expand into the appropriate form on the plot. Note that issue #1 occurs with or without a LatexString as the ylabel and that LatexString expansion is not working for other string values either.
Sample plot, code, and data are provided below to reproduce. I am using the Juno editor with the Plotly backend on Windows.
using Plots, DelimitedFiles, LaTeXStrings
plotly(linewidth=3,titlefont=18,legendfont=16,guidefont=18,tickfont=14,formatter=:plain)
data=readdlm("hoopstress.txt",skipstart=1)
r=data[:,2]
σθ=data[:,end-1:end]
plot(r,σθ,label=["Simplified Vessel" "Full Vessel"],xlabel="r",ylabel=L"\sigma_\theta")
Length Simple Full
1 0. 53280 56859
2 9.4e-2 52158 55405
3 0.1875 51036 53951
4 0.28125 49915 52498
5 0.375 48793 51044
6 0.46875 47671 49590
7 0.5625 46550 48136
8 0.65625 45428 46682
9 0.75 44307 45228
10 0.84375 43185 43774
11 0.9375 42063 42320
12 1.0312 40942 40866
13 1.125 39883 39411
14 1.2187 39256 38780
15 1.3125 38629 38150
16 1.4062 38002 37519
17 1.5 37375 36888
18 1.5938 36748 36257
19 1.6875 36121 35627
20 1.7813 35494 34996
21 1.875 34867 34365
22 1.9688 34239 33735
23 2.0625 33612 33104
24 2.1562 32985 32473
25 2.25 32389 31842
26 2.3437 31998 31441
27 2.4375 31607 31039
28 2.5312 31216 30637
29 2.625 30825 30235
30 2.7187 30434 29833
31 2.8125 30043 29431
32 2.9062 29652 29029
33 3. 29261 28628
34 3.0938 28870 28226
35 3.1875 28479 27824
36 3.2813 28088 27422
37 3.375 27714 27020
38 3.4688 27452 26693
39 3.5625 27190 26367
40 3.6563 26927 26040
41 3.75 26665 25714
42 3.8438 26403 25387
43 3.9375 26141 25061
44 4.0313 25879 24734
45 4.125 25617 24408
46 4.2187 25354 24081
47 4.3125 25092 23755
48 4.4062 24830 23428
49 4.5 24568 23102
I filed a PR to solve the problem, which has just been merged into master :-)
So in the future you will be able to do
plotly(linewidth=3,titlefont=18,legendfont=16,guidefont=18,tickfont=14,formatter=:plain)
r = 1:10
σθ = [100000 ./ (1:10) .+ 10000, 100000 ./ (1:10) .- 1000 .+ 10000]
plot(r , σθ, label=["Simplified Vessel" "Full Vessel"],
xlabel = "r",
ylabel = L"\sigma_\theta\\\color{white}.",
yformatter = :plain,
include_mathjax = "cdn",
extra_kwargs = :plot)
if you are connected to the internet.
For for local use, if Conda and IJulia are installed and the TeX fonts are copied as described in my previous answer, you can do the following.
import Conda.ROOTENV
function local_mathjax()
joinpath(ROOTENV, "Lib", "site-packages", "notebook", "static", "components", "MathJax",
"MathJax.js?config=TeX-AMS-MML_HTMLorMML-full")
end
plotly(linewidth=3,titlefont=18,legendfont=16,guidefont=18,tickfont=14,formatter=:plain)
r = 1:10
σθ = [100000 ./ (1:10) .+ 10000, 100000 ./ (1:10) .- 1000 .+ 10000]
plot(r , σθ, label=["Simplified Vessel" "Full Vessel"],
xlabel = "r",
ylabel = L"\sigma_\theta\\\color{white}.",
yformatter = :plain,
include_mathjax = local_mathjax(),
extra_kwargs = :plot)
The formatting of y-axis numbers is now realised via yformatter = :plain and the space in the y-title was achieved by adding a line with a white-formatted dot.
Of course, you could also place a mathjax copy anwhere on your system and put the link in the includ_mathjax argument.
More details on the usage can be found in the PR.
Happy coding!
Latex output seems to be currently broken in Plotly.
I read, that for some people it depends on the browser. I couldn't get it to work on neither Edge nor Chrome.
Concerning the overlap it is, unfortunately, the standard setting of plotly itself. However, plotly and also the Julia package Plotly provide the yaxis.automargin = true parameter to overwrite this setting.
If you want additional space you can achieve this by adding a non-empty line to your title, which is done by adding the html code <br>
Below I have supplied an example code to achieve this in Plotly. (Currently, the plotly() backend of Plotsdoes not support passing backend-specific parameters. But there is work going on to achieve this.)
using Plotly
trace1 = Plotly.scatter(Dict(
"x" => [1, 2, 3, 4],
"y" => [1, 4, 9, 16] .* 1000000,
"name" => L"\alpha_{1c} = 352 \pm 11 \text{ km s}^{-1}",
"type" => "scatter")
)
trace2 = Plotly.scatter(Dict(
"x" => [1, 2, 3, 4],
"y" => [0.5, 2, 4.5, 8] .* 1000000,
"name" => L"\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}",
"type" => "scatter")
)
data = [trace1, trace2]
# standard layout (shortens numbers by SI prefix)
layout1 = Layout(xaxis = attr(title = L"\sqrt{(n_\text{c}(t|{T_\text{early}}))}"),
yaxis = attr(title = L"$d, r \text{ (solar radius)}")
)
# sets the number format to "0", i.e. without prefixing
layout2 = Layout(xaxis = attr(title = L"\sqrt{(n_\text{c}(t|{T_\text{early}}))}"),
yaxis = attr(title = L"$d, r \text{ (solar radius)}",
tickformat = "0")
)
# forces automargin
layout3 = Layout(xaxis = attr(title = L"\sqrt{(n_\text{c}(t|{T_\text{early}}))}"),
yaxis = attr(title = L"$d, r \text{ (solar radius)}",
tickformat = "0",
automargin = true)
)
# adds an additional space by adding a line to the title
# note that Plotly seems to accept html code ...
layout4 = Layout(xaxis = attr(title = L"\sqrt{(n_\text{c}(t|{T_\text{early}}))}"),
yaxis = attr(title = L"$d, r \text{ (solar radius)}<br> ",
tickformat = "0",
automargin = true)
)
p1 = Plotly.plot(data, layout1)
p2 = Plotly.plot(data, layout2)
p3 = Plotly.plot(data, layout3)
p4 = Plotly.plot(data, layout4)
Switching to the PyPlot backend fixed both problems straight away.
Switching to the GR backend fixed the LaTeX issue, but made the label overlap worse.
I had some success with the Plotly backend by adding using Plots.PlotMeasures to the top of the script and adding left_margin=80px to either the plot or plotly statements. However, the result wasn't really satisfactory. The margin additions did not affect label spacing with the GR backend.
I still would like to find a solution for directly modifying the plot label positioning since plotly has better interactivity.
Currently plotly does not provide the mathjax environment, but Jupyter does. However, Jupyter by default, does not install the TeX fonts, which seem to be Mathjax default fonts by now.
In order to fix this you have to copy the original mathjax distribution to the directory where jupyter keeps its static files.
download MathJax-2.7.7.zip
copy the jax-folder from the MathJax-2.7.7.zip to C:\Users\<username>\.julia\conda\3\Lib\site-packages\notebook\static\components\MathJax or whereever the files are stored on your system. Note that there might be more MathJax folders, e.g. C:\Users\<username>\.julia\conda\3\pkgs\notebook-6.0.3-py36_0\Lib\site-packages\notebook\static\components\MathJax, but only one is the true source for the server.
Now you can either use Plotly
using Plotly
trace1 = Plotly.scatter(Dict(
"x" => [1, 2, 3, 4],
"y" => [1, 4, 9, 16] .* 1000000,
"name" => L"\alpha_{1c} = 352 \pm 11 \text{ km s}^{-1}",
"type" => "scatter")
)
trace2 = Plotly.scatter(Dict(
"x" => [1, 2, 3, 4],
"y" => [0.5, 2, 4.5, 8] .* 1000000,
"name" => L"\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}",
"type" => "scatter")
)
data = [trace1, trace2]
layout = Layout(xaxis = attr(title = L"\sqrt{(n_\text{c}(t|{T_\text{early}}))}"),
yaxis = attr(title = L"\sigma_\theta\\?",
tickformat = "0",
automargin = true)
)
p = Plotly.plot(data, layout)
(I couldn't find a quick solution for a line break in LaTeX syntax. The linebreak was only kept if I added a character. Maybe, someone else can contribute here ;-) )
or Plots:
using Plots, LaTeXStrings
plotly()
Plots.plot(1:4, [[1,4,9,16], [0.5, 2, 4.5, 8]],
labels = [L"\alpha_{1c} = 352 \pm 11 \text{ km s}^{-1}" L"\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}"],
xlabel = L"\sqrt{(n_\text{c}(t|{T_\text{early}}))}",
ylabel = L"d, r \text{ (solar radius)}"
)
In order to make it work in Juno make sure that the Conda package is installed and the mathjax fonts are copied as described above. Then make the following definitions:
import Plots.plotly_html_head
import Conda.ROOTENV
function mathjax()
mathjaxdir = joinpath(ROOTENV, "Lib\\site-packages\\notebook\\static\\components\\MathJax")
mathjaxfile = joinpath(mathjaxdir, "MathJax.js?config=TeX-AMS-MML_HTMLorMML-full")
return """<script type="text/javascript" src="file://$mathjaxfile"></script>"""
end
function plotly_html_head(plt::Plots.Plot)
local_file = ("file://" * Plots.plotly_local_file_path)
plotly = Plots.use_local_dependencies[] ? Plots.local_file : Plots.plotly_remote_file_path
if Plots.isijulia() && !Plots.ijulia_initialized[]
# using requirejs seems to be key to load a js depency in IJulia!
# https://requirejs.org/docs/start.html
# https://github.com/JuliaLang/IJulia.jl/issues/345
display("text/html", """
<script type="text/javascript">
requirejs([$(repr(plotly))], function(p) {
window.Plotly = p
});
</script>
""")
ijulia_initialized[] = true
end
return """$(mathjax())
<script src=$(repr(plotly))></script>"""
end

Highcharts custom pattern fill shows different stroke width

I'm trying to create a custom pattern fill for highcharts.
It's a horizontal dashed line with alternating starting points from one row to another (the first start at 0,0 the second at 3,10 and so on).
I edited the Highcharts JSfiddle example replacing the custom pattern with the following (here you can find my "final" version) :
color: {
pattern: {
path: {
d: 'M 0 0 H 8 M 14 0 H 22 M 3 10 H 19',
strokeWidth: 0.5
},
width: 22,
height: 20
}
}
The problem is the the two rows of lines have different width.
I can't find any parameter in the documentation to fix this.
I don't know if the problem is in my pattern definition or a highcharts bug.
Any thoughts?
The path as-is moves first to 0,0 and then 14,0, and finally 3,10:
d: 'M 0 0 H 8 M 14 0 H 22 M 3 10 H 19'
You can change that to 0,1 and then 14,1, and then 3,11 and the lines are the same width:
d: 'M 0 1 H 8 M 14 1 H 22 M 3 11 H 19'
The lines starting at 0,0 are centred on the boundary meaning that half the line gets cut off, so just moving them all down by 1 ensures that the whole line is visible.
Updated Fiddle

Prawn::Errors::CannotFit: Table's width was set too small to contain its contents

I am trying to create a table in Prawn using the following code however the columns widths do not suite well for me with columns width I have now. Given that I still have some free space, I want to expand a little bit the second and last columns so I increased both of them to 55.mm and 20.mm accordingly but I am getting an error
Prawn::Errors::CannotFit: Table's width was set too small to contain its contents (min width 450.70866141732284, requested 442).
Why does expanding a column width throws Tabe too small error?
I have calculated the total width of the columns:
9.mm + 45.mm + 20.mm + 20.mm + 20.mm + 30.mm + 15.mm + 20.mm #=> 507.40157480314963
I don't understand it. What am I doing wrong?
bounding_box [0, 792], width: 612, height: 792 do
bounding_box [30, 792], width: 442, height: 792 do
line_items_table
end
end
def line_items_table
table line_item_rows, table_options do
row(0).background_color = TABLE_BACKGROUND_COLOR
columns(2..-1).align = :right
end
end
def table_options
{
cell_style: { border_width: 0 },
column_widths: TABLE_COLUMN_WIDTHS,
header: true,
# width: 160.mm
}
end
def line_item_rows
[TABLE_HEADERS]
end
TABLE_COLUMN_WIDTHS = { 0 => 9.mm, 1 => 45.mm, 2 => 20.mm, 3 => 20.mm, 4 => 30.mm, 5 => 15.mm, 6 => 15.mm }.freeze
TABLE_HEADERS = [I18n.t('pdf.headers.row_num'), I18n.t('pdf.headers.name'),
I18n.t('pdf.headers.quantity'), I18n.t('pdf.headers.price_net_amount'), I18n.t('pdf.headers.net_amount'),
I18n.t('pdf.headers.vat'), I18n.t('pdf.headers.gross_amount')].freeze
#Table headers above are: 'No', 'Name', 'Qauntity', 'Net Sale', 'Net amount', 'Gross amount', 'VAT'
Table's width was set too small to contain its contents (min width 450.7, requested 442)
meaning your total column width must below 442, and your total currently is 450.7,
you should change it to below 442
you have line code that set 442
bounding_box [30, 792], width: 442, height: 792 do
if you want to set bigger then my suggestion you should change it first

Calculate the minimum and maximum in cvInRangeS

cvCvtColor(frame, hsv_frame, CV_BGR2HSV);
cvInRangeS(hsv_frame, hsv_min, hsv_max, thresholded);
I try to follow blue ball. To determine the maximum and minimum I open a picture I took with the camera, open it MS paint and doubles at (180/240) result out of me in H
And (255/240) the result of S and L
then i recive the next values:
108 113 115 112 105 H
145 40 107 129 143 S
97 129 96 102 124 L
So I chose the next values:
CvScalar hsv_min = cvScalar( 105, 40, 96 );
CvScalar hsv_max = cvScalar( 115, 140, 130);
But when I try to follow it hardly ever see him
Am I wrong calculation? or what can i do to improve the result?
First of all why do you convert your image to HSV and then talk about HSL? If I'm not mistaken they are different color spaces.
To determinate blue color using HSV color space use this range:
Min (H/S/V): 90, 50, 50
Max (H/S/V): 130, 255, 255
Also this online converter should help you.
And don't forget that Hue value after converting image to HSV using CV_BGR2HSV code is in range [0..180], while using CV_BGR2HSV_FULL will give you range [0..360].

Resources