Python graph- change axis marker colours and legend border colours
Tag : python , By : Michael Gunderson
Date : March 29 2020, 07:55 AM
wish of those help If you just want to use rcParams, the proper parameters are xticks.color and yticks.color. I can't seem to find a key for the legend frame color. You can set that (along with the tick colors) programmatically though. import pylab
pylab.plot([1,2,3],[4,5,6], label ='test')
lg = pylab.legend()
lg.get_frame().set_edgecolor('blue')
ax = pylab.axes()
for line in ax.yaxis.get_ticklines():
line.set_color('blue')
for line in ax.xaxis.get_ticklines():
line.set_color('blue')
for label in ax.yaxis.get_ticklabels():
label.set_color('blue')
for label in ax.xaxis.get_ticklabels():
label.set_color('blue')
pylab.show()
|
Optimal visualisation of ggplot colours: changing order of colours, keeping original factor ordering
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I love the default ggplot2 colour, but with the dataset I'm using, it's very important the reader can tell the difference between two adjacent categories. This is difficult with the default colours, as I have 10 categories and therefore the generated colours are very similar between neighbouring factor groups. , To shuffle the order of the colors, you could use require(scales)
n <- length(levels(data$category)) # number of colors
cols <- hue_pal(h = c(0, 360) + 15,
c = 100, l = 65,
h.start = 0, direction = 1)(n)[order(sample(1:n, n))] # color palette in random order
ggplot(data,aes(x,y,colour=category))+stat_smooth(alpha=0, size=2) +
scale_color_manual(values = cols)
|
ggplot legend colours in complex plot
Tag : r , By : Daniel Halsey
Date : March 29 2020, 07:55 AM
Does that help Change the colour= call in aes in the geom_line calls to whatever you want to appear in the legend: add_lines1 <- lapply(s1, function(i) geom_line(aes_q(y = as.name(i), colour = "Line1")))
add_lines2 <- lapply(s2, function(i) geom_line(aes_q(y = as.name(i), colour = "Line2")))
add_lines3 <- lapply(s3, function(i) geom_line(aes_q(y = as.name(i), colour = "Line3")))
add_lines4 <- lapply(s4, function(i) geom_line(aes_q(y = as.name(i), colour = "Line4")))
p1 <- ggplot(data, aes(x = time)) + scale_color_manual(values=c("orange","yellow","white","green"))
p1 <- p1 + add_lines1 + add_lines2
p2 <- ggplot(data, aes(x = time)) + scale_color_manual(values=c("orange","yellow","white","green"))
p2 <- p2 + add_lines1 + add_lines3 + add_lines4
|
how to add legend to ggplot barplot with individual colours for each bar
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I'm new to ggplot, so hopefully this is an easy question. I've made a stacked barplot with colours for each segment given in col: , You were close! Move fill = col to aes: library(ggplot2)
a <- data.frame(var = rep(seq(1:2),2), val = seq(1:4))
col <- rainbow(n = 4)
ggplot(a, aes(x = var, y = val, fill = col)) +
geom_bar(stat = 'identity') +
scale_fill_manual(values = col)
|
My figure legend colours do not match my graph line colours?
Date : March 29 2020, 07:55 AM
this will help You are basically plotting the error bar over the inital line plot. As default the plt.errorbar is a line plot with error bar on each point. # Gives a red line plot
plot1, = plt.plot(x, b, 'r-')
# Gives a '#1f77b4' (default first color) line plot with error bars
plt.errorbar(x, b, xerr=None, yerr=mated_E)
import pandas as pd
import matplotlib.pyplot as plt
df_mated = pd.read_csv("file1.txt", sep='\t', header=0)
df_mated['Average'] = df_mated.mean(axis=1)
df_mated['SEM'] = df_mated.loc[:, :'Average'].sem()
mated_E = df_mated['SEM'].tolist()
b = df_mated['Average'].tolist()
plot1, = plt.plot(x, b, 'r-')
# Plot only the y-errorbar, not the line connecting the datapoint
plt.errorbar(x, b, xerr=None, yerr=mated_E, ls='')
df_unmated = pd.read_csv("file2.txt", sep='\t', header=0)
df_unmated['Average'] = df_unmated.mean(axis=1)
df_unmated['SEM'] = df_unmated.loc[:, :'Average'].sem()
unmated_E = df_unmated['SEM'].tolist()
c = df_unmated['Average'].tolist()
plot2, = plt.plot(x, c, 'b-')
# Plot only the y-errorbar, not the line connecting the datapoint
plt.errorbar(x, c, xerr=None, yerr=unmated_E, ls='')
plt.xlabel('Position')
plt.ylabel('Average Read Depth')
plt.legend([plot1,plot2],["Mated", "Unmated"])
plt.show()
|