how to solve value error x must be 1d pie chart - jupyter-notebook

Using fifa 2018 data to plot a preferred foot pie chart. initialized left and right, getting error when calling them in plt.
left = fifa.loc[fifa['Preferred Foot'] == 'Left'].count(0)
right = fifa.loc[fifa['Preferred Foot'] == 'Right'].count(0)
print(left[0])
print(right[0])
plt.pie(x=[left,right])
plt.show()

Related

Line plot in Julia shows a weird line... is this a bug?

I am trying to plot two series (each has 2,000 points) using Plots.plot function in Julia 1.7.3.
When drawing the line plot, Julia displays a weird line that goes from an end of the line to the other across the plane as above. There is a strange orange diagonal, and there's no data point on that line. Does anyone know if this is a bug, or is there any error with my code?
Em_mu = [a_grid.+Es[1] res.mu[:,1]]
Unem_mu = [a_grid.+Es[2] res.mu[:,2]]
Em_dat = DataFrame(wealth = Em_mu[:,1], density1 = Em_mu[:,2])
Unem_dat = DataFrame(wealth = Unem_mu[:,1], density2 = Unem_mu[:,2])
wealth_mat = outerjoin(Em_dat, Unem_dat, on=:wealth)
replace!(wealth_mat.density1, missing => 0)
replace!(wealth_mat.density2, missing => 0)
disallowmissing!(wealth_mat)
wealth_mat = Matrix(wealth_mat)
Plots.plot(wealth_mat[:,1], wealth_mat[:,2:3], title = "Distribution")
It looks like your second series is not sorted by its x values. The line plot connects data points with a line so if it's not sorted you get weird lines like that.

Highstocks Highcharter Polar plot breaking zoom bar

So I have this plot right here that I've taken from a tutorial
x <- quantmod::getSymbols("GOOG", auto.assign = FALSE)
highchart(type = "stock")%>%
hc_add_series(x)
And what I would like to do it transform this plot to a polar plot, so I added polar = TRUE
highchart(type = "stock")%>%
hc_add_series(x) %>%
hc_chart(polar = TRUE)
And it seems to work pretty fine except one thing : you can see that the zoom bar at the bottom of the plot is totally broken (The range can go until the year 3000...)
How can I fix it?

Legend outside plot does not work with plotyy in Octave

I am trying to create a plot in Octave (using v4.4.1 on Windows) using plotyy and putting the legend outside the plot (because the data covers all the usable space inside the graph). The following MVCE should reproduce the issue fairly well:
% Generate some random data to reproduce the issue
data = rand(1000,10);
data(:,1:8) = data(:,1:8)-0.5;
data(:,9:10) = data(:,9:10)+30;
timedate = linspace(737310,737313,size(data,1));
data_labels={'1';'2';'3';'4';'5';'6';'7';'8';'9';'10'};
% Plot the data
figure('Name','MVCE','Position',[300 200 1000 600])
[ax,h1,h2] = plotyy(timedate,data(:,1:8),timedate,data(:,9:10));
set(h2,'Visible','on');
datetick(ax(1),'x','HH:MM:SS')
datetick(ax(2),'x','HH:MM:SS')
ylim(ax(1),[-1 1])
ylim(ax(2),[20 50])
xlabel('Date & time')
ylabel(ax(1),'Something')
ylabel(ax(2),'Something else')
title('plotyy graph with legend problem')
[hl,hlo] = legend([h1;h2],data_labels,'location','eastoutside');
grid on
This the output of the code using the gnuplot graphics toolkit:
As you can see, the legend does not go outside the plot, and the second y axis is not visible (it looks like part of the plot is actually truncated).
I have tried using the qt and fltk graphics toolkits, which give issues of their own:
With qt graphics toolkit
With fltk graphics toolkit
Can anoybody suggest a fix or at least workaround? Does the same issue also happen in MATLAB or is it Octave-specific?
EDIT
Using the suggestion in Tasos' answer, I managed to almost make it work with gnuplot:
% Plot the data
figure('Name','MVCE','Position',[300 200 1000 600])
[ax,h1,h2] = plotyy(timedate,data(:,1:8),timedate,data(:,9:10));
set(h2,'Visible','on');
datetick(ax(1),'x','HH:MM:SS')
datetick(ax(2),'x','HH:MM:SS')
ylim(ax(1),[-1 1])
ylim(ax(2),[20 50])
ax1Pos = get(ax(1), 'position');
ax2Pos = get(ax(2), 'position');
ax1Pos(3) = ax1Pos(3) * 0.73;
ax2Pos(3) = ax2Pos(3) * 0.73;
set(ax(1), 'position', ax2Pos);
set(ax(2), 'position', ax2Pos);
xlabel('Date & time')
ylabel(ax(1),'Something')
ylabel(ax(2),'Something else')
title('plotyy graph with legend problem')
[hl,hlo] = legend([h1;h2],data_labels,'location','eastoutside');
pos = get(hl,'Position');
pos(1) = 0.9;
set(hl,'Position',pos)
grid on
Which produces:
Apart from the fact that the legend overlays with the second y axis label (which it doesn't on my screen, only when printing to jpg), the problem is that Octave appears to plot two legends on top of each other for some reason: one with the first set of data attached to the first set of axes, and one with the complete set of data, for both axes right on top of the first legend. This is obviously wrong, and trying to set the Visible property of hl to off deletes both legends, not just the one.
UPDATED: deals with both legend placement and OpenGL precision affecting graph.
Regarding the problem of the legend not appearing exactly in the position you want it to, you can manually adjust the position of all axes involved in a figure, to place them exactly where you want.
Regarding the problem of OpenGL being unable to deal with the precision involved when adding small numbers to a large number, plot the graph with only the small numbers involved, and then simply adjust the xticklabels to correspond to the numbers you desire.
Full code below:
% Generate some random data to reproduce the issue
data = rand(1000,10);
data(:,1:8) = data(:,1:8)-0.5;
data(:,9:10) = data(:,9:10)+30;
t_offset = 737310;
timedate = linspace(0,3,size(data,1));
data_labels={'1';'2';'3';'4';'5';'6';'7';'8';'9';'10'};
% Plot the data
figure('Name','MVCE','Position',[300 200 1000 600])
[ax,h1,h2] = plotyy(timedate,data(:,1:8),timedate,data(:,9:10));
set(h2,'Visible','on');
ylim(ax(1),[-1 1])
ylim(ax(2),[20 50])
ylabel(ax(1),'Something')
ylabel(ax(2),'Something else')
title('plotyy graph with legend problem')
[hl,hlo] = legend([h1;h2],data_labels,'location','eastoutside');
set(hl, 'position', get(hl, 'position') .* [0.975, 1, 0.975, 1] )
grid on
ax1Pos = get(ax(1), 'position'); ax2Pos = get(ax(2), 'position');
ax1Pos(3) = ax1Pos(3) * 0.95; ax2Pos(3) = ax2Pos(3) * 0.95;
set(ax(1), 'position', ax2Pos); set(ax(2), 'position', ax2Pos);
XTicks = get(ax(1), 'xtick');
set(ax(1), 'xticklabel', datestr(XTicks + t_offset, 'HH:MM:SS'))
xlabel('Date & time')
set(ax(2), 'xtick', []);
Output:

Single bar stacked chart in DC

I am trying to populate a single column stacked bar chart. It is just a sum of one value stacked over the other i.e. the sum of 'LB' experiments stacked over the 'Random' experiments.
Since I need to give a dimension value to the chart I have assumed a Dim variable with 1 as its value for both lb and random.
I am getting the above described data using the following code:
d3.csv("file:///D:/Optus/LARS T&L/Dashboard/html/dummy2.csv",function(error, experiments) {
var ndx = crossfilter(experiments),
rDim = ndx.dimension(function(d) {return d.Dim;});
var lb = rDim.group().reduceSum(function(d){return d.LBRandom=="LB"?d.Contacted:0;});
var ran = rDim.group().reduceSum(function(d){return d.LBRandom=="Random"?d.Contacted:0;});
Although when I am trying to plot this data, the browser only displays the the axis and no data is plotted:
Code for plotting:
chart
.width(768)
.height(480)
.x(d3.scale.ordinal())
.y(d3.scale.linear().domain([0,200000]))
.brushOn(false)
.dimension(rDim)
.group(lb)
.stack(ran)
.render();
});
Can anyone help me out with this? It's my 1st day working with d3, dc & crossfilters libraries.
Thanks!

ERROR: longer object length is not a multiple of shorter object length

I have a dataset which has multiple longitude and latitude of different places in the UK. I am trying to use those figured to create multiple pie charts on the map. Whats essential is just making a pie chart on the map. NOTE: I can make a single pie chart if i hardcode the latitude and longitude.
Code:
floating.pie(xpos = area$longditude, ypos = area$Latitude,x=1, radius=0.2, col="orange")
Area:
area <- sqlQuery(con, "SELECT top 3 geo.Latitude, geo.longditude FROM dbo.[Geography]")
The dataset is:
55.9500, 3.1833
54.8659, -2.3522
54.0167, 2.6333
53.5667, 1.2000
52.8311, 1.3278
52.5000, 1.8333
52.3555, -1.1743
51.5000, 51.5000
51.4833, 3.1833
51.3167, 0.5000
50.9600, -3.2200
The error i am getting is:
Warning messages:
1: In cos(t2p) * radius + xpos :
longer object length is not a multiple of shorter object length
2: In sin(t2p) * yradius + ypos :
longer object length is not a multiple of shorter object length
Note: Using all of the above code, i dont get seperate piecharts at all. not sure how to do this, help please.
As an example view
plotting pie graphs on map in ggplot
What you see in the webpaghe is what i want i ve got it working nearly, just need to know how to tell R to differentiate those values i provide using Area and to plot them correctly as a single pie chart.
I was able to plot multiple float pie charts, but I had to use an infamous for loop.
area1<-data.frame(Longitude = c(10,30, 50),
Latitude = c(5, 25, 50))
plot(0:100,type="n",main="Floating Pie test",xlab="",ylab="",axes=FALSE)
for(i in 1:length(area1$Longitude)){
floating.pie(xpos = area1$Longitude[i],
ypos = area1$Latitude[i],edges = 200, x=1, radius=10, col="orange")
}

Resources