scatter-plot

How to change scatter plot color according to certain rule

ぃ、小莉子 提交于 2020-02-16 10:41:32
问题 I have to do a scatter plot that has colors depending on a third variable. If the variable is between 0 and 1, give "blue", 1-2, red, 2-3, purple, 3-4, green, 4-5 gray. How can I do that ? x = [1,2,3,4,5] y = [3,4,2,3,4] c = [1,2,4,0.5,5] 回答1: If you want specific boundaries for the colormap you can use mpl.colors.BoundaryNorm together with mpl.colors.ListedColormap . import matplotlib.pyplot as plt import matplotlib as mpl x = [1,2,3,4,5] y = [3,4,2,3,4] c = [1,2,4,0.5,5] cmap = mpl.colors

How to change scatter plot color according to certain rule

白昼怎懂夜的黑 提交于 2020-02-16 10:41:07
问题 I have to do a scatter plot that has colors depending on a third variable. If the variable is between 0 and 1, give "blue", 1-2, red, 2-3, purple, 3-4, green, 4-5 gray. How can I do that ? x = [1,2,3,4,5] y = [3,4,2,3,4] c = [1,2,4,0.5,5] 回答1: If you want specific boundaries for the colormap you can use mpl.colors.BoundaryNorm together with mpl.colors.ListedColormap . import matplotlib.pyplot as plt import matplotlib as mpl x = [1,2,3,4,5] y = [3,4,2,3,4] c = [1,2,4,0.5,5] cmap = mpl.colors

How can I highlight a dot in a cloud of dots with Matplotlib?

蓝咒 提交于 2020-02-06 08:24:18
问题 I'm using Matplotlib and my goal is highlighting some points in a scatterplot. I used the following code: $colors = {'true':'red', 'false':'blue'} plt.scatter(data[T[j]], data[T[i]], c=data['upgrade'].apply(lambda x: colors[x]) $ This code let my dots being red if the condition is "true", else blue. I haven't any problem until I had the following example: 20k dots and just 1 is TRUE. The plot that I obtained can't display my only point, because I have a cloud full of blue dots (2k) and just

How can I highlight a dot in a cloud of dots with Matplotlib?

别说谁变了你拦得住时间么 提交于 2020-02-06 08:22:33
问题 I'm using Matplotlib and my goal is highlighting some points in a scatterplot. I used the following code: $colors = {'true':'red', 'false':'blue'} plt.scatter(data[T[j]], data[T[i]], c=data['upgrade'].apply(lambda x: colors[x]) $ This code let my dots being red if the condition is "true", else blue. I haven't any problem until I had the following example: 20k dots and just 1 is TRUE. The plot that I obtained can't display my only point, because I have a cloud full of blue dots (2k) and just

How to conciliate dots annotation in Matplotlib scatter plot with manual limit setting?

我的梦境 提交于 2020-02-05 04:37:28
问题 I'm trying to conciliate dots annotation in a Matplotlib scatter plot with a manual limit setting, but I either got an error message or I get a design problem. Here is my code : fig, ax = plt.subplots(figsize = (20,10)) #manual limit setting plt.axis([-2,3,-2.5,5]) plt.scatter(x, y) for i, txt in enumerate(n): #dot annotation ax.annotate(txt, (x[i], y[i])) Here is a screen cap of the output (I got the final scatter plot as a small rectangle located in the left corner of a big white rectangle

Matplotlib Legend on Scatterplot from pandas dataframe

喜欢而已 提交于 2020-01-30 08:45:06
问题 I am trying to get the legend right on the figure below. It should be just 'green', 'blue' and 'red' with the corresponding color. But it is all over the place. the code is below: import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame({ 'category':['blue','green','red','blue','green','red','blue','green','red'], 'attempts':[8955,7881,6723,100,200,300,4567,876,54], 'success':[3000,7500,2000, 256,4567,4567,7665,543,43] }) fig,ax = plt.subplots() plt.scatter(df['attempts'],df[

r: Plotting each column against each column

笑着哭i 提交于 2020-01-30 05:14:41
问题 I have a dataframe ("data") with 7 columns (2 Factor, 5 num). The first column is containing the names of 7 different countries and in the following columns I have collected data for different parameters (like population, GDP etc.) characterizing each country. In the last column a factor variable assigns which continent the respective country belongs to. The data looks like this: structure(list(Country = structure(c(5L, 4L, 7L, 2L, 1L, 6L, 3L), .Label = c("Brazil", "Chile", "China", "France",

How to conciliate dots annotation in Matplotlib scatter plot with manual limit setting?

こ雲淡風輕ζ 提交于 2020-01-28 02:55:06
问题 I'm trying to conciliate dots annotation in a Matplotlib scatter plot with a manual limit setting, but I either got an error message or I get a design problem. Here is my code : fig, ax = plt.subplots(figsize = (20,10)) #manual limit setting plt.axis([-2,3,-2.5,5]) plt.scatter(x, y) for i, txt in enumerate(n): #dot annotation ax.annotate(txt, (x[i], y[i])) Here is a screen cap of the output (I got the final scatter plot as a small rectangle located in the left corner of a big white rectangle

Scatterplot Marker Size proportional to axis value - why is the number of pixels for the x and y axis different for aspect='equal'?

二次信任 提交于 2020-01-23 11:45:29
问题 My question is as far as I see closely related to this post. I need to plot some data with marker size strictly proportional to the value of the axes. (Already asked the question here). My approach is the following: Create empty scatterplot for pixel reference Scatter 2 points on the lower left and upper right corner Limit the axes to exactly these two points use transData.transform to get the pixel values of those two points get the pixel distance as the difference in pixel number of these

Scatterplot Marker Size proportional to axis value - why is the number of pixels for the x and y axis different for aspect='equal'?

此生再无相见时 提交于 2020-01-23 11:45:29
问题 My question is as far as I see closely related to this post. I need to plot some data with marker size strictly proportional to the value of the axes. (Already asked the question here). My approach is the following: Create empty scatterplot for pixel reference Scatter 2 points on the lower left and upper right corner Limit the axes to exactly these two points use transData.transform to get the pixel values of those two points get the pixel distance as the difference in pixel number of these