rbokeh color argument- legend messes up on R 3.6 - rbokeh

The legend generated for an ly_bar figure that uses a variable for a color argument has a title of base::quote("variable_name"). This is only a problem when generating graphs on R 3.6.
figure() %>%
ly_bar(variety, yield, color = year, data = lattice::barley, hover = TRUE) %>%
theme_axis("x", major_label_orientation = 90)
The graph legend should say "year" instead of base::quote("year").

Related

Altair: merge multiple identical legends when using resolve_scale to merge color and shape properties

Following a frequent issue in Altair:
merging legends 1
merging legends 2
combining color and shape
I want to plot several point series with line plots and point marks visualized both with different colors, shapes, and stroke dashes:
This works as expected when using resolve_scale
x = np.arange(0, 5, 0.1)
mask = np.ones_like(x)
mask[::2] = 0
df = pd.DataFrame({
"x": x,
"y": np.sin(x)*mask + np.cos(x)*(1-mask),
"y2": np.sin(2*x)*mask + np.cos(2*x)*(1-mask) ,
"col": mask
})
base= alt.Chart(df).mark_line(point=True, size=1).encode(
alt.X("x:Q"),
color = alt.Color("col:N"),
shape = alt.Shape("col:N"),
strokeDash = alt.StrokeDash("col:N")
).resolve_scale(color="independent", shape="independent", strokeDash="independent")
base.encode(alt.Y("y:Q"))
But when concatenated with other charts with a different y-value multiple identical legends appear:
base.encode(alt.Y("y:Q")) | base.encode(alt.Y("y2:Q"))
I understand this is the purpose of "resolve_scale", would really appreciate a workaround.
not using the resolve_scale method or using it on the concatenated chart would get me a legend with every visualized property (color, shape, etc) set apart.
You have set the color, shape, and strokeDash to one thing: "col:N". If you want them to be independent, then define them as different things.
base= alt.Chart(df).mark_line(point=True, size=1).encode(
alt.X("x:Q"),
color = alt.Color("col:N"),
shape = alt.Shape("col:N"),
strokeDash = alt.StrokeDash("col:N")
)
h = base.encode(alt.Y("y:Q"), color=alt.value('red')) | base.encode(alt.Y("y2:Q"), color=alt.value('blue')).resolve_scale(color="independent", shape="independent", strokeDash="independent")
as for a workaround, you could go into the h.hconcat[0].encoding and h.hconcat[1].encoding and change the map to be whatever you want for vega-lite to read. At that point I'd just use a different library.
Hopefully this helps.

Cannot get the color to work in a biplot from the RDA procedure in Vegan

I have run RDA from Vegan, and cannot generate four different colors in the "sites" on the plot that correspond to the Group trait which really is countries. The problem is colvec[Group] that fails to link up the four colors with the four different countries. I avoided this for the legend by just spelling out the colors for each country, and that worked (produced a legend with the correct colors for the country). When I take out the col = colvec[Group], the plot does produce the points ("sites"), but they all are black in color and do not differentiate the countries. I have been using the suggested code at:
https://fromthebottomoftheheap.net/2012/04/11/customising-vegans-ordination-plots/
Can anyone help suggest a modification that would produce the correct colors in the points (sites)?
Thanks much.
plot(R EDUNENVONLY)
scl <- 2
par(pty="s") #makes plot square
colvec <- c("dark green", "red", "purple", "blue")
Group <- ENVIR$Group
plot(REDUNENVONLY, choices = c(1, 2), type = "n", xlim = c(-1.5, 1.5))
with(ENVIR, points(REDUNENVONLY, display = "sites",
bg = colvec[Group], col = colvec[Group],
scaling = scl, pch = 21))
text(REDUNENVONLY, display="bp", scaling = scl, cex = 1,col=1) # add black arrows
with(ENVIR, legend("topright", legend = c("CCHINA", "JAPAN", "KOREA", "NCHINA"),
col = c("dark green", "red", "purple", "blue"), pch = c(16,16)))
[![Biplot produced from code above](https://i.stack.imgur.com/zTqHW.png)](https://i.stack.imgur.com/zTqHW.png)
[![Biplot without col = colvec[Group] ](https://i.stack.imgur.com/G4XjU.png)](https://i.stack.imgur.com/G4XjU.png)
I have tried various other solutions, and I know ggplot is another possibility, but this would require more learning (I am a novice at R) and surely some simply change to the present code will get this to work.

PyPlot - Tricky axis color and labeling issues

I am fairly new to Matplotlib. This idea behind this figure is to graph temperature highs and lows. I've run into trouble with the xaxis and right yaxis.
For the xaxis, the color of the font doesn't want to change even though I call tick_params(labelcolor='#b6b6b6'). Also, the dates should only span from Jan - Dec. For unknown reasons, Matplotlib is prepending an extra Dec and appending an extra Jan, causing the text to flow outside of the graph's spine bounds. I want to remove these extra months.
For the right yaxis, I'm not sure I understand the use of subplots properly. I want to convert the ˚C temperatures in the left yaxis to ˚F and use the converted temps for the secondary yaxis.
Here's some code to reproduce something similar to what I've got.
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.dates as dates
import matplotlib.ticker as ticker
# generate some data to plot
highs = np.linspace(0, 40, 365) # these numbers will escalate instead of fluctuate, but the problem with the axes will still be the same.
lows = np.linspace(-40, 0, 365)
date_rng = pd.date_range('1/1/2015', '12/31/2015', freq='D')
data = {'highs': highs, 'lows': lows}
to_plot = pd.DataFrame(data, index=date_rng)
fig, ax = plt.subplots()
# plot the basic data
lines = ax.plot(date_rng, to_plot['lows'], '-',
date_rng, to_plot['highs'], '-')
# get the axes reference
ax1 = plt.gca()
# fill in between the lines
ax1.fill_between(date_rng,
to_plot['lows'], to_plot['highs'],
facecolor='#b6b6b6', # gradient fillbetween
alpha=.2)
# set the xaxis to only 12 months and space the names.
ax1.xaxis.set_major_locator(dates.MonthLocator())
ax1.xaxis.set_minor_locator(dates.MonthLocator(bymonthday=15, interval=1))
ax1.xaxis.set_major_formatter(ticker.NullFormatter())
ax1.xaxis.set_minor_formatter(dates.DateFormatter('%b'))
for tick in ax1.xaxis.get_minor_ticks():
tick.tick1line.set_markersize(0)
tick.tick2line.set_markersize(0)
tick.label1.set_horizontalalignment('center')
# add a right y axis and set all yaxis properties
ax1.set_ylim([-50, 50])
# change the color and sizes scheme
info_colors = '#b6b6b6'
bold_colors = '#777777'
# graph lines
ax1.lines[0].set_color('#e93c00') # top redish orange
ax1.lines[1].set_color('#009ae9') # btm blue
plt.setp(lines, lw=.8, alpha=1)
# spines
ax.spines['top'].set_visible(False)
for pos in ['bottom', 'right', 'left']:
ax.spines[pos].set_edgecolor(info_colors)
# set the title
plt.title('Record Temps, 2005-15: Ann Arbour, MI', fontsize=10, color=bold_colors)
# ticks
ax1.tick_params(axis='both', color=info_colors, labelcolor=info_colors, length=5, direction='out', pad=7, labelsize=8)
# add a legend and edit its properties
leg = plt.legend(['Highs','Lows'], frameon=False, loc=0, fontsize='small')
for text in leg.get_texts():
text.set_color(info_colors)
plt.ylabel('˚C', color=info_colors)
# set extra yaxis label
ax2 = ax.twinx()
ax2.set_ylabel('˚F', color=info_colors)
ax2.tick_params('y', colors=info_colors)
To change the color of the minor labels, put the following code after ax1.xaxis.set_minor_formatter(dates.DateFormatter('%b')):
ax1.xaxis.set_tick_params(which='minor', colors=info_colors)

How to choose correct value range of green colour from histogram charts

I tried to segment just leaves from plant image. I spend 2 weeks googling about how to extract correct range value for green colour from the histogram of the hue, saturation and value colour space. I used the following codes:
hsv=rgb2hsv(INSUM);
H1=hsv(:,:,1);
figure, imshow(H1);
H2=hsv(:,:,2);
figure, imshow(H2);
H3=hsv(:,:,3);
figure, imshow(H3)
H1(H1(:)==0)=[];
H2(H2(:)==0)=[];
H3(H3(:)==0)=[];
figure,imhist(H1);
figure,imhist(H2);
figure,imhist(H3);
limitUpperH = 0.3; limitLowerH = 0.19;
limitUpperS = 1; limitLowerS = 0.95;
limitUpperV = 0.6; limitLowerV = 0.02;
LOGICH = (hsv(:,:,1)<limitUpperH) & (hsv(:,:,1)>limitLowerH);
LOGICS = (hsv(:,:,2)<limitUpperS) & (hsv(:,:,2)>limitLowerS);
LOGICV = (hsv(:,:,3)<limitUpperV) & (hsv(:,:,3)>limitLowerV);
LOGIC = LOGICH & LOGICS & LOGICV;
figure() imshow(LOGIC);
I choose the limitUpper and limitLower for the H, S and V works for just one image by trial and error and they give good result for just one image, but when I apply these values on other images it doesn’t work.
I read many things and saw many examples about the HSV and image histogram but none say how to extract green range of h, s and v from histogram chart. Can any one help me?

Why sometimes the bars with bar or hist have no border?

I noticed that sometimes, when I plot the bars using the functions bar() or hist(), the bars plotted have no border. They are a little bit less nice to see, and I would prefer the border or a little bit of space between them.
The figure shows what I got now, plotting three different datasets. The third graph is zoomed in order to show the lack of space between bars.
I get there this has something to do with the 'histc' parameters in bar function. Without the histc parameters the bars have some space between each others, but then the bar will be centered on the edges values, whereas I want the edges values to be, well, EDGES of each bar.
This is (the relevant part of) the code I used:
[...]
if edges==0
%these following lines are used to take the min and max of the three dataset
maxx=max(cellfun(#max, reshape(data,1,size(data,1)*size(data,2))));
minn=min(cellfun(#min, reshape(data,1,size(data,1)*size(data,2))));
edges=minn:binW:maxx+binW;
end
[...]
y{k}=histc(data{r,c}, edges);
bar(edges,y{k} , 'histc');
[...]
I think if you change the color of your bar plots you'll see that there actually is a border it just doesn't show up very well. You can also change the width of the bars so that they are more distinct.
% something to plot
data = 100*rand(1000,1);
edges = 1:100;
hData = histc(data,edges);
figure
subplot(2,1,1)
h1 = bar(edges,hData,'histc');
% change colors
set(h1,'FaceColor','m')
set(h1,'EdgeColor','b')
% Change width
subplot(2,1,2)
h1 = bar(edges,hData,0.4,'histc');
The EdgeColor and LineWidth properties of the Barseries object control the bar outlines. Try using the code and playing with the red, green, blue, and width values to get a better result.
red = 1;
green = 1;
blue = 1;
width = 3;
h = bar(edges,y{k} , 'histc');
set(h,'EdgeColor',[red green blue],'LineWidth',width);