如何更改 matplotlib 中散点图的背景颜色?
目前我有
import matplotlib.pyplot as plt
plt.scatter(X, Y, c=T, marker='o', s=(0.005*r), linewidth=0, cmap=cm.coolwarm)
plt.scatter(X_stars, Y_stars, marker='o', s=(0.00000005*r), color='white')
plt.savefig(filename, format='ps')
Run Code Online (Sandbox Code Playgroud)
我希望背景是黑色,而不是白色。我已经改变了facecolor和edgecolor黑色,但没有预期的效果。设置transparent=True使其透明,以便我可以在 Photoshop 中更改背景,但它必须在 matplotlib 中工作,因为我有大量的绘图。
我正在尝试使用Matplotlib的2d散点图函数绘制一些数据,同时在x和y轴上生成投影直方图.我发现的例子来自matplotlib图片库(pylab_examples示例代码:scatter_hist.py).
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import NullFormatter
# the random data
x = np.random.randn(1000)
y = np.random.randn(1000)
nullfmt = NullFormatter() # no labels
# definitions for the axes
left, width = 0.1, 0.65
bottom, height = 0.1, 0.65
bottom_h = left_h = left+width+0.02
rect_scatter = [left, bottom, width, height]
rect_histx = [left, bottom_h, width, 0.2]
rect_histy = [left_h, bottom, 0.2, height]
# start with a rectangular Figure
plt.figure(1, figsize=(8,8))
axScatter = plt.axes(rect_scatter) …Run Code Online (Sandbox Code Playgroud) 在所有这些示例中,点/气泡大小基于第三因素,例如size.
但是,在我的数据中,我只有2个变量,xval和yval.
library("ggplot2")
xval <- c("0","0.5","0.25","0","0")
yval <- c("1","0.5","0.25","0.25","1")
df.test <- data.frame(xval,yval)
df.test
p <- ggplot(df.test, aes(x = xval, y = yval)) + geom_point()
p
Run Code Online (Sandbox Code Playgroud)
这是 df.test
xval yval
1 0 1
2 0.5 0.5
3 0.25 0.25
4 0 0.25
5 0 1
Run Code Online (Sandbox Code Playgroud)
这是 p
我想要的是每个点/气泡大小取决于该坐标的观测值的出现次数.例如,(0,1)将是其他点的两倍大.我想避免在我的数据框中添加第3列,并让R自动执行.
我不知道这是否可以在不必过多地使用数据的情况下完成...任何见解都会非常感激:)
我正在使用 matplotlib 绘制纬度经度坐标中的变量。问题是此图像不能包含轴或边框。我已经能够删除轴,但我的图像周围的白色填充必须完全删除(请参阅下面代码中的示例图像:http : //imgur.com/a/W0vy9)。
我尝试了 Google 搜索中的几种方法,包括这些 StackOverflow 方法:
如何删除 matplotlib 子图中的填充/边框(已解决)
但在去除空白方面没有任何作用。如果您有任何建议(即使是放弃 matplotlib 并尝试使用另一个绘图库),我将不胜感激!
这是我正在使用的代码的基本形式,它显示了这种行为:
import numpy as np
import matplotlib
from mpl_toolkits.basemap import Basemap
from scipy import stats
lat = np.random.randint(-60.5, high=60.5, size=257087)
lon = np.random.randint(-179.95, high=180, size=257087)
maxnsz = np.random.randint(12, 60, size=257087)
percRange = np.arange(100,40,-1)
percStr=percRange.astype(str)
val_percentile=np.percentile(maxnsz, percRange, interpolation='nearest')
#Rank all values
all_percentiles=stats.rankdata(maxnsz)/len(maxnsz)
#Figure setup
fig = matplotlib.pyplot.figure(frameon=False, dpi=600)
#Basemap code can go here
x=lon
y=lat
cmap = matplotlib.cm.get_cmap('cool') …Run Code Online (Sandbox Code Playgroud) 我正在考虑使用谷歌图表来分散情节.所有示例都具有外部依赖性,我想避免这种情况,因为这是一个没有外部Internet访问的Intranet应用程序.
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {packages: ['corechart']});
google.charts.setOnLoadCallback(drawChart);
...
</script>
Run Code Online (Sandbox Code Playgroud)
我可以简单地在本地复制loader.js,还是有一些我需要担心的更复杂的问题?我问的原因是我尝试这样做而且没有用,所以我试图弄清楚我所做的事情是否存在根本缺陷或者我可能会遇到一个无关紧要的问题.
我正在尝试映射非数字 y 和 x,但由于某种原因它不起作用。
例如
xLabels: ["January", "February", "March", "April", "May", "June", "July"],
yLabels: ['Request Added', 'Request Viewed', 'Request Accepted', 'Request Solved', 'Solving Confirmed'],
Run Code Online (Sandbox Code Playgroud)
当我尝试改变时:
data: ['Request Added', 'Request Viewed']
Run Code Online (Sandbox Code Playgroud)
和
data: [{x: "January", y: 'Request Added'}, ...]
Run Code Online (Sandbox Code Playgroud)
图表不显示任何东西
我也尝试使用 scales.yAxis.ticks.callback 来修改和映射数组,但这也没有奏效。
[0: 'Request Added', 1: 'Request Viewed']
Run Code Online (Sandbox Code Playgroud)
编辑:基本上我需要这样的东西
Request Added x x
Request Viewed x
Request Accepted x x
January, Feb, March
Run Code Online (Sandbox Code Playgroud)
基本上是一个副本:https : //answers.splunk.com/answers/85938/scatter-plot-with-non-numeric-y-values.html
这也建议映射到一个数组,但 Y-ticks 中的回调没有任何意义..?当我添加labelY : [1,2,3,4,5,6]回调“值”的第三个参数时,它等于[-2-1 0 1 2].
我正在使用Alpha来设置ggplot中平滑线的透明度,但是我只能在围绕拟合线的误差带中获得透明度。
我的代码如下:
z1 <- rnorm(10)
z2 <- z1 ^ 2
error <- rnorm(10, 0.25)
y <- 1 + 0.5 * z1 + error
data1 <- data.table(y, z1, z2)
ggplot(data1) +
geom_point(aes(x = z1, y = y), color = "blue", size = 3) +
geom_point(aes(x = z2, y = y), color = "red", size = 3) +
geom_smooth(method = lm, aes(x = z1, y = y), color = "blue", size = 2, alpha = 0.1) +
geom_smooth(method = lm, aes(x = …Run Code Online (Sandbox Code Playgroud) 我一直在寻找 SO 以增加 relplot 中的图例/色调大小。
plt.rcParams["axes.labelsize"] = 20
g = sns.relplot(x='Time(days)', y='Duration Total (s)', hue='Outcome', data=t1,height=15, aspect=1, s=50);
plt.suptitle("a_10",fontsize=25, fontweight='bold')
Run Code Online (Sandbox Code Playgroud)
我似乎无法绕过它。有这么多混合引用,这有点令人困惑。
使用以下代码。
plt.scatter(z1,y1, s = 0.5, color = 'blue')
plt.scatter(z2,y2, s = 0.5, color = 'orange')
Run Code Online (Sandbox Code Playgroud)
我尝试使用,plt.fill_between()但要使其工作,我需要在x_axis(需要做类似的事情plt.fill_between(x,y1,y2))上有相同的数据。是否有任何其他功能可能对此有所帮助,或者我只是使用fill_between错误。
scatter-plot ×10
matplotlib ×4
python ×4
charts ×2
ggplot2 ×2
r ×2
alpha ×1
bubble-chart ×1
chart.js ×1
colormap ×1
dataframe ×1
excel ×1
histogram ×1
javascript ×1
legend ×1
linechart ×1
python-3.x ×1
scatter ×1
smoothing ×1
vba ×1