aesthetics

How to add black border to matplotlib 2.0 `ax` object In Python 3?

我与影子孤独终老i 提交于 2019-12-05 11:53:22
I've been using style sheets in matplotlib lately. I really like how clean the seaborn-white looks and I want to be able to add the border to other styles like ggplot or seaborn-whitegrid . How can I add a black border around my ax object from fig, ax = plt.subplots() ? import pandas as pd import numpy as np from collections import * Se_data = pd.Series(Counter(np.random.randint(0,10,100))) with plt.style.context("seaborn-whitegrid"): fig, ax = plt.subplots() Se_data.plot(kind="barh", ax=ax, title="No Border") with plt.style.context("seaborn-white"): fig, ax = plt.subplots() Se_data.plot(kind=

Filling in the area under a line graph in ggplot2: geom_area()

半城伤御伤魂 提交于 2019-12-04 00:00:50
问题 For the data: def.percent period valence 1 6.4827843 1984-1985 neg 2 5.8232425 1985-1986 neg 3 -2.4003260 1986-1987 pos 4 -3.5994399 1987-1988 pos If I add a line to the points, how can I use ggplot2 to color the area under the line [ geom_area() ] with different colors for the valence values "neg" and "pos"? I tried this: ggplot(data, aes(x=period, y=def.percent, group = 1)) + geom_area(aes(fill=valence)) + geom_line() + geom_point() + geom_hline(yintercept=0) But R returns the error: Error:

Dash in column name yields “object not found” Error

前提是你 提交于 2019-12-02 04:12:57
I have a function to generate scatter plots from data, where an argument is provided to select which column to use for coloring the points. Here is a simplified version: library(ggplot2) plot_gene <- function (df, gene) { ggplot(df, aes(x, y)) + geom_point(aes_string(col = gene)) + scale_color_gradient() } where df is a data.frame with columns x , y , and then a bunch of gene names. This works fine for most gene names; however, some have dashes and these fail: print(plot_gene(df, "Gapdh")) # great! print(plot_gene(df, "H2-Aa")) # Error: object "H2" not found It appears the gene variable is

Plot point markers and lines in different hues but the same style with seaborn

旧街凉风 提交于 2019-12-01 16:58:56
Given the data frame below: import pandas as pd df = pd.DataFrame({ "n_index": list(range(5)) * 2, "logic": [True] * 5 + [False] * 5, "value": list(range(5)) + list(range(5, 10)) }) I'd like to use color and only color to distinguish logic in a line plot, and mark points on value s. Specifically, this is my desired output (plotted by R ggplot2 ): ggplot(aes(x = n_index, y = value, color = logic), data = df) + geom_line() + geom_point() I tried to do the same thing with seaborn.lineplot , and I specified markers=True but there was no marker: import seaborn as sns sns.set() sns.lineplot(x="n

ggpairs plot with heatmap of correlation values

夙愿已清 提交于 2019-12-01 06:09:39
My question is twofold; I have a ggpairs plot with the default upper = list(continuous = cor) and I would like to colour the tiles by correlation values (exactly like what ggcorr does). I have this: I would like the correlation values of the plot above to be coloured like this: library(GGally) sample_df <- data.frame(replicate(7,sample(0:5000,100))) colnames(sample_df) <- c("KUM", "MHP", "WEB", "OSH", "JAC", "WSW", "gaugings") ggpairs(sample_df, lower = list(continuous = "smooth")) ggcorr(sample_df, label = TRUE, label_round = 2) I had a brief go at trying to use upper = list(continuous = wrap

Filling in the area under a line graph in ggplot2: geom_area()

[亡魂溺海] 提交于 2019-12-01 03:19:25
For the data: def.percent period valence 1 6.4827843 1984-1985 neg 2 5.8232425 1985-1986 neg 3 -2.4003260 1986-1987 pos 4 -3.5994399 1987-1988 pos If I add a line to the points, how can I use ggplot2 to color the area under the line [ geom_area() ] with different colors for the valence values "neg" and "pos"? I tried this: ggplot(data, aes(x=period, y=def.percent, group = 1)) + geom_area(aes(fill=valence)) + geom_line() + geom_point() + geom_hline(yintercept=0) But R returns the error: Error: Aesthetics can not vary with a ribbon This same code works for a different dataset, I don't understand

Plot point markers and lines in different hues but the same style with seaborn

点点圈 提交于 2019-11-30 03:35:07
问题 Given the data frame below: import pandas as pd df = pd.DataFrame({ "n_index": list(range(5)) * 2, "logic": [True] * 5 + [False] * 5, "value": list(range(5)) + list(range(5, 10)) }) I'd like to use color and only color to distinguish logic in a line plot, and mark points on value s. Specifically, this is my desired output (plotted by R ggplot2): ggplot(aes(x = n_index, y = value, color = logic), data = df) + geom_line() + geom_point() I tried to do the same thing with seaborn.lineplot, and I

Aesthetics must either be length one, or the same length as the dataProblems

女生的网名这么多〃 提交于 2019-11-27 19:41:28
I would like to make a plot with X values as a subset of the measurement and Y-values as another subset of the measured data. In the example as below, I have 4 products p1, p2, p3 and p4. Each are priced according to their skew, color and version. I would like to create a multi-facet plot that depicts the P3 products (Y-axis) vs P1 products (X-axis). My attempt as below has failed miserably with the following error: Error: Aesthetics must either be length one, or the same length as the dataProblems:subset(price, product == "p1"), subset(price, product == "p3") library(ggplot2) product=c("p1",

Closing the lines in a ggplot2 radar / spider chart

本秂侑毒 提交于 2019-11-27 16:56:14
问题 I need a flexible way to make radar / spider charts in ggplot2. From solutions I've found on github and the ggplot2 group, I've come this far: library(ggplot2) # Define a new coordinate system coord_radar <- function(...) { structure(coord_polar(...), class = c("radar", "polar", "coord")) } is.linear.radar <- function(coord) TRUE # rescale all variables to lie between 0 and 1 scaled <- as.data.frame(lapply(mtcars, ggplot2:::rescale01)) scaled$model <- rownames(mtcars) # add model names as a

What is the difference between aes and aes_string (ggplot2) in R

ⅰ亾dé卋堺 提交于 2019-11-27 06:38:53
问题 With missing background in informatics I have difficulties to understand the differences between aes and aes_string in ggplot2 and its implications for daily usage. From the description ( ?aes_string ) I was able to understand that both describe how variables in the data are mapped to visual properties (aesthetics) of geom . Furthermore it is said that aes uses non-standard evaluation to capture the variable names. whereas aes_string uses regular evaluation . From example code it is clear