scatter-plot

Force ggplot2 scatter plot to be square shaped

不问归期 提交于 2019-11-27 14:19:07
问题 I can force ggplot2 scatter plot to be square shaped with the same x and y scaling using xlim() and ylim() , but it needs manual calculation of the limits. Is there any more convenient way of doing it? By square shape I mean two requirements: The same scale on x and y axis. The equal length of x and y axis. 回答1: If you want to make the distance scale points the same, then use coord_fixed(): p <- ggplot(...) p <- p + coord_fixed() # ratio parameter defaults to 1 i.e. y / x = 1 If you want to

How to add a border around a chart created via arrange.grid in gridExtra encompassing a set ggplot2 scatter plots

烈酒焚心 提交于 2019-11-27 14:06:59
问题 I'm using the code below: # Libs require(ggplot2); require(gridExtra); require(grid) # Generate separate charts chrts_list_scts <- list() # Data data("mtcars") # A chrts_list_scts$a <- ggplot(mtcars) + geom_point(size = 2, aes(x = mpg, y = disp, colour = as.factor(cyl))) + geom_smooth(aes(x = mpg, y = disp), method = "auto") + xlab("MPG") + ylab("Disp") + theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), legend.position = "none") # B chrts_list_scts$b

Plotting a horizontal line on multiple subplots in python using pyplot

白昼怎懂夜的黑 提交于 2019-11-27 12:56:57
问题 I am plotting three subplots on the same page. I want to draw a horiZontal line through all the subplots. Following is my code and the resultant graph: (You can notice I can get the horizontal line on one of the plots, but not all) gs1 = gridspec.GridSpec(8, 2) gs1.update(left=0.12, right=.94, wspace=0.12) ax1 = plt.subplot(gs1[0:2, :]) ax2 = plt.subplot(gs1[3:5, :], sharey=ax1) ax3 = plt.subplot(gs1[6:8, :], sharey=ax1) ax1.scatter(theta_cord, density, c = 'r', marker= '1') ax2.scatter(phi

Transparency for Poly3DCollection plot in matplotlib

纵然是瞬间 提交于 2019-11-27 12:30:23
I am trying to draw some objects with the fabulous Matplotlib package for Python. These objects consist of points implemented with plt.scatter() and patches implemented with Poly3DCollection . I would like to have the patches with a slight transparency so that the points and edges behind the patches can be seen. Here the code and plot I already generated. Seems I am almost there, just missing the feature of transparency. Interestingly, if I first plot the Ploy3DCollection and afterwards the scatter points, the points can be seen, but not the edges. Anyone having a suggestion for me? from

Get data from plot with matplotlib

痴心易碎 提交于 2019-11-27 11:59:15
I'm using matplotlib in python to build a scatter plot. suppose I have the following 2 data lists. X=[1,2,3,4,5] Y=[6,7,8,9,10] then I use X as the X-axis value and Y as the Y-axis value to make a scatter plot. So I will have a picture with 5 scattering points on it, right? Now the question: is it possible to build connection for these 5 points with the actual data. For example, when I click on one of these 5 points, it can tell me what original data I have used to make this point? thanks in advance Using a slightly modified version of Joe Kington's DataCursor : import matplotlib.pyplot as plt

Fixing color in scatter plots in matplotlib

徘徊边缘 提交于 2019-11-27 11:35:55
问题 I want to fix the color range on multiple scatter plots and add in a colorbar to each plot (which will be the same in each figure). Essentially, I'm fixing all aspects of the axes and colorspace etc. so that the plots are directly comparable by eye. For the life of me, I can't seem to figure out all the various ways of fixing the color-range. I've tried vmin, vmax, but it doesn't seem to do anything, I've also tried clim(x,y) and that doesn't seem to work either. This must come up here and

How can a data ellipse be superimposed on a ggplot2 scatterplot?

冷暖自知 提交于 2019-11-27 11:29:43
I have an R function which produces 95% confidence ellipses for scatterplots. The output looks like this, having a default of 50 points for each ellipse (50 rows): [,1] [,2] [1,] 0.097733810 0.044957994 [2,] 0.084433494 0.050337990 [3,] 0.069746783 0.054891438 I would like to superimpose a number of such ellipses for each level of a factor called 'site' on a ggplot2 scatterplot, produced from this command: > plat1 <- ggplot(mapping=aes(shape=site, size=geom), shape=factor(site)); plat1 + geom_point(aes(x=PC1.1,y=PC2.1)) This is run on a dataset, called dflat which looks like this: site geom

Multivariate (polynomial) best fit curve in python?

不羁的心 提交于 2019-11-27 11:16:15
问题 How do you calculate a best fit line in python, and then plot it on a scatterplot in matplotlib? I was I calculate the linear best-fit line using Ordinary Least Squares Regression as follows: from sklearn import linear_model clf = linear_model.LinearRegression() x = [[t.x1,t.x2,t.x3,t.x4,t.x5] for t in self.trainingTexts] y = [t.human_rating for t in self.trainingTexts] clf.fit(x,y) regress_coefs = clf.coef_ regress_intercept = clf.intercept_ This is multivariate (there are many x-values for

How to jitter text to avoid overlap in a ggplot2 scatterplot?

不羁的心 提交于 2019-11-27 10:46:51
问题 I would like to create a clean version of a scatterplot of text labels in ggplot2. The goal is to represent visually the increasing values associated with about 25 items. I am already using "position_jitter," but I wonder if I can do better. Here is some mock data: title <- rep("A Really Rather Long Text Label", 25) value <- runif(25, 1,10) spacing <- seq(1:25) df <- data.frame(title, value, spacing, stringsAsFactors = FALSE) And here is the code that generates the graph: library(ggplot2)

Scatterplot Contours In Matplotlib

一世执手 提交于 2019-11-27 09:48:54
问题 I have a massive scatterplot (~100,000 points) that I'm generating in matplotlib. Each point has a location in this x/y space, and I'd like to generate contours containing certain percentiles of the total number of points. Is there a function in matplotlib which will do this? I've looked into contour(), but I'd have to write my own function to work in this way. Thanks! 回答1: Basically, you're wanting a density estimate of some sort. There multiple ways to do this: Use a 2D histogram of some