scatter-plot

Force ggplot2 scatter plot to be square shaped

旧时模样 提交于 2019-11-28 22:23:41
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. mys 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 ensure that the resulting plot is square then you would also need to specify the x and y limits to be

Plotting a horizontal line on multiple subplots in python using pyplot

陌路散爱 提交于 2019-11-28 20:31:30
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_cord, density, c = 'r', marker= '1') ax3.scatter(r_cord, density, c = 'r', marker= '1') ax1.set_xlabel(

Individual alpha values in scatter plot

前提是你 提交于 2019-11-28 18:47:27
问题 I'm wondering if it is possible to have individual alpha values for each point to be plotted using the scatter function of Matplotlib. I need to plot a set of points, each one with its alpha value. For example, I have this code to plot some points def plot_singularities(points_x, p, alpha_point, file_path): plt.figure() plt.scatter(points_x, points_y, alpha=alpha_point) plt.savefig(file_path + '.png', dpi=100) plt.close() All my points_x , points_y and alpha_point have n values. However, I

Fixing color in scatter plots in matplotlib

情到浓时终转凉″ 提交于 2019-11-28 18:44:34
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 there, I can't be the only one that wants to compare various subsets of data amongst plots... so, how do

Multivariate (polynomial) best fit curve in python?

帅比萌擦擦* 提交于 2019-11-28 18:22:11
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 each case). So, X is a list of lists, and y is a single list. For example: x = [[1,2,3,4,5], [2,2,4,4,5

Any easy way to plot a 3d scatter in Python that I can rotate around?

廉价感情. 提交于 2019-11-28 17:36:32
Currently I'm using matplotlib to plot a 3d scatter and while it gets the job done, I can't seem to find a way to rotate it to see my data better. Here's an example: import pylab as p import mpl_toolkits.mplot3d.axes3d as p3 #data is an ndarray with the necessary data and colors is an ndarray with #'b', 'g' and 'r' to paint each point according to its class ... fig=p.figure() ax = p3.Axes3D(fig) ax.scatter(data[:,0], data[:,2], data[:,3], c=colors) ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') fig.add_axes(ax) p.show() I'd like a solution that lets me do it during execution time but

Scatterplot Contours In Matplotlib

杀马特。学长 韩版系。学妹 提交于 2019-11-28 16:35:30
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! Basically, you're wanting a density estimate of some sort. There multiple ways to do this: Use a 2D histogram of some sort (e.g. matplotlib.pyplot.hist2d or matplotlib.pyplot.hexbin ) (You could also display the results as

gnuplot: Plot in correct scale & position on top of image

旧街凉风 提交于 2019-11-28 13:50:06
My problem is drawing a plot atop an image. The image is not just meant to be a nice background but should line up with the plot. The plot is many colored points representing a car's speed and position in a coordinates system. That works. Now I want to line up the plot with an image of the road and there I have problems. The data file looks like this: -60.2501 106.115 0 0 -68.1729 98.0388 0 0 [...] x-pos, y-pos,speed, ignore last number Here is what I have so far: set multiplot set yrange [-1280:1280] set xrange [-1280:1280] # set xrange [-1470:1280] set size ratio 1 plot 'BL.jpg' binary

Coloring each point of a chart based on data using sequential or divergent color scales

百般思念 提交于 2019-11-28 13:08:37
How can I colour the individual points on a scatter chart based on values in my spreadsheet? For example, how can I create the following chart: Where the x-data are in column U, the y-data are in column V and the colour data are in column T How can I create a divergent colourmap instead of a sequential one? Full example on GitHub: https://github.com/DanGolding/Scatter-plot-with-color-grading-in-Excel If your colour data have only a few discrete values, the easiest way is to plot it as different series as shown here . However, if you have sequential data, you will need to use VBA to loop

multiple scatter plots with matplotlib and strings on the x-axis.

那年仲夏 提交于 2019-11-28 11:52:41
问题 I'm trying to make three scatter plots in one figure. I tried it this way. Do an import first. import matplotlib.pyplot as plt Define the variables and make one figure that contains three scatter plots. c_pop = [0.410, -0.094, -0.111, -0.106, -0.090, 0.070, -0.043, -0.181, 0.221] c_labels = ['ll120', 'll123', 'll124', 'll27', 'll28', 'll30', 'll446, n12', 'll447, n86', 'll471'] pre_lo = [-0.493] post_lo = [0.145] lo_label = ['lo'] fig = plt.figure() ax1 = fig.add_subplot(111) ax1.scatter(c