标签: line-plot

如何在ggplot中更改线宽?

数据链接:使用 的数据

我的代码:

ccfsisims <- read.csv(file = "F:/Purdue University/RA_Position/PhD_ResearchandDissert/PhD_Draft/GTAP-CGE/GTAP_NewAggDatabase/NewFiles/GTAP_ConsIndex.csv", header=TRUE, sep=",", na.string="NA", dec=".", strip.white=TRUE)
ccfsirsts <- as.data.frame(ccfsisims)
ccfsirsts[6:24] <- sapply(ccfsirsts[6:24],as.numeric)
ccfsirsts <- droplevels(ccfsirsts)
ccfsirsts <- transform(ccfsirsts,sres=factor(sres,levels=unique(sres)))

library(ggplot2)

#------------------------------------------------------------------------------------------
#### Plot of food security index for Morocco and Turkey by sector
#------------------------------------------------------------------------------------------

#_Code_Begin...

datamortur <- melt(ccfsirsts[ccfsirsts$region %in% c("TUR","MAR"), ]) # Selecting regions of interest
datamortur1 <- datamortur[datamortur$variable %in% c("pFSI2"), ] # Selecting the food security index of interest
datamortur2 <- datamortur1[datamortur1$sector %in% c("wht","gro","VegtFrut","osd","OthCrop","VegtOil","XPrFood"), ] # Selecting food sectors of interest
datamortur3 …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 line-plot

112
推荐指数
5
解决办法
25万
查看次数

ggplot()行透明度

如何更改ggplot()图表中线条的透明度(即直方图,线图等)?

例如,考虑以下代码:

data <- data.frame(a=rnorm(100), b = rnorm(100,.5,1.2))
data <- melt(data)
colnames(data) <- c("Category", "Intensity")
p <- ggplot(data, aes(x=Intensity))
p <- p + geom_density(aes(color=Category), size=2, alpha=.4)
print(p)
Run Code Online (Sandbox Code Playgroud)

我预计线条会透明(如alpha=.4),但它们不是.

在此输入图像描述

r histogram ggplot2 line-plot

23
推荐指数
1
解决办法
2万
查看次数

使用pyplot在python中绘制多个子图上的水平线

我正在同一页面上绘制三个子图.我想在所有子图中绘制一条horiZontal线.以下是我的代码和结果图:(您可以注意到我可以在其中一个图上获得水平线,但不是全部)

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('Theta (radians)')
ax1.set_ylabel('Galaxy count')
ax2.set_xlabel('Phi (radians)')
ax2.set_ylabel('Galaxy count')
ax3.set_xlabel('Distance (Mpc)')
ax3.set_ylabel('Galaxy count')
plt.ylim((0,0.004))
loc = plticker.MultipleLocator(base=0.001)
ax1.yaxis.set_major_locator(loc)

plt.axhline(y=0.002, xmin=0, xmax=1, hold=None)

plt.show()
Run Code Online (Sandbox Code Playgroud)

这会生成以下内容: 在此输入图像描述

同样,我希望我在最后一个子图上绘制的线也出现在前两个子图上.我怎么做?

python matplotlib scatter-plot subplot line-plot

20
推荐指数
2
解决办法
5万
查看次数

删除seaborn lineplot图例标题

我想从我的seaborn lineplot图例中删除标题.我尝试使用这个答案无济于事:

import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
fmri = sns.load_dataset("fmri")
fig, ax = plt.subplots()
g = sns.lineplot(x="timepoint", y="signal", hue="event", data=fmri, ax=ax)
ax.legend().set_title('')
Run Code Online (Sandbox Code Playgroud)

Seaborn lineplot仍然带有'event'标题

如果我尝试将标题设置为,我会得到相同的结果None.有趣的是,将标题设置为其他内容似乎优先于现有标题:

ax.legend().set_title('Something else')
Run Code Online (Sandbox Code Playgroud)

Seaborn lineplot仍然有前置标题

看起来seaborn几乎将标题视为隐藏的传奇条目.我该如何解决这个问题?

python matplotlib line-plot seaborn

18
推荐指数
3
解决办法
7969
查看次数

如何使用Python Pandas绘制堆叠事件持续时间(Gantt Charts)?

我有一个Pandas DataFrame,其中包含流量计开始测量流量的日期以及该站退役的日期.我想生成一个以图形方式显示这些日期的图表.以下是我的DataFrame示例:

index StationId amin amax 40623 UTAHDWQ-5932100 1994-07-19 13:15:00 1998-06-30 14:51:00 40637 UTAHDWQ-5932230 2006-03-16 13:55:00 2007-01-24 12:55:00 40666 UTAHDWQ-5932240 1980-10-31 16:00:00 2007-07-31 11:35:00 40697 UTAHDWQ-5932250 1981-06-11 17:45:00 1990-08-01 08:30:00 40728 UTAHDWQ-5932253 2006-06-28 13:15:00 2007-01-24 13:35:00 40735 UTAHDWQ-5932254 2006-06-28 13:55:00 2007-01-24 14:05:00 40742 UTAHDWQ-5932280 1981-06-11 15:30:00 2006-08-22 16:00:00 40773 UTAHDWQ-5932290 1992-06-10 15:45:00 1998-06-30 11:33:00 40796 UTAHDWQ-5932750 2005-10-03 16:30:00 2005-10-22 15:00:00 40819 UTAHDWQ-5983753 2006-04-25 09:56:00 2006-04-25 10:00:00 40823 UTAHDWQ-5983754 2006-04-25 11:05:00 2008-04-08 12:16:00 40845 UTAHDWQ-5983755 2006-04-25 13:50:00 2008-04-08 09:10:00 40867 UTAHDWQ-5983756 …

python time-series matplotlib pandas line-plot

14
推荐指数
2
解决办法
2万
查看次数

如何在极坐标图中连接 geom_line 的端点和起点(coord_polar)?

我有点难以将极坐标图中的一条线的端点与起点连接起来。

我的数据:

df <- structure(list(ri = c(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360),
                 n = c(329L, 315L, 399L, 700L, 919L, 757L, 656L, 918L, 1117L, 976L, 878L, 803L, 811L, 1072L, 1455L, 1642L, 1891L, 1688L, 1553L, 1841L, 2061L, 2321L, 2498L, 2080L, 1595L, 1080L, 1002L, 953L, 729L, 604L, 538L, 489L, 535L, 455L, 328L, …
Run Code Online (Sandbox Code Playgroud)

geometry r ggplot2 line-plot

6
推荐指数
1
解决办法
1918
查看次数

是否可以用seaborn绘制6列以上的图?

是否可以使用seaborn.lineplot绘制6列以上的图形?

当我尝试绘制它时,我收到以下错误消息:

These `style` levels are missing dashes: {'LOGAN', 'HB20S', 'GOL'}
Run Code Online (Sandbox Code Playgroud)

如果我为6列的数据框建立索引,它将起作用。

这是有效的代码:

sns.lineplot(data=movida_2.iloc[:,:6])
Run Code Online (Sandbox Code Playgroud)

plot matplotlib line-plot seaborn python-3.6

6
推荐指数
1
解决办法
2579
查看次数

您可以将四分位距绘制为 seaborn 线图上的误差带吗?

我正在使用 seaborn lineplot ( https://seaborn.pydata.org/generated/seaborn.lineplot.html )绘制时间序列数据,并绘制中位数而不是平均值。示例代码:

import seaborn as sns; sns.set()
import matplotlib.pyplot as plt

fmri = sns.load_dataset("fmri")
ax = sns.lineplot(x="timepoint", y="signal", estimator = np.median, data=fmri)
Run Code Online (Sandbox Code Playgroud)

我希望误差带显示四分位距而不是置信区间。我知道我可以ci = "sd"用于标准偏差,但是有没有一种简单的方法来添加 IQR?我想不明白。

谢谢!

python graph line-plot seaborn

5
推荐指数
2
解决办法
2873
查看次数

Seaborn 线图对数刻度

我在向绘图中添加对数 X 轴时遇到问题。我想使用方法显示基于样本大小的结果AB并且C.

我的数据框:

            A         B         C
15   0.733333  0.613333  0.733333
30   0.716667  0.693333  0.766667
59   0.733684  0.678485  0.745763
118  0.796667  0.726087  0.779661
236  0.817862  0.788333  0.838983
470  0.832125  0.814468  0.836170
Run Code Online (Sandbox Code Playgroud)

我正在努力做的事情:

sample_count = np.around(np.logspace(math.log10(15),math.log10(470),6))
sample_count = sample_count.astype(int)

sns.set_style('whitegrid')
g_results=sns.lineplot(data=results,dashes=0,markers=['o','o','o'])
g_results.set(xticks=sample_count)
g_results.set(xscale='log')
Run Code Online (Sandbox Code Playgroud)

然而,结果并不是我真正想要的,因为滴答声完全消失了:

电流输出

如果没有最后xscale一行,它看起来像这样,当然这是线性比例,但这次使用正确的刻度:

没有 xscale 的电流输出

我想要实现的是这样的:

期望的输出

我很感激你对我的问题的帮助。

python line-plot seaborn

5
推荐指数
1
解决办法
1279
查看次数

Seaborn lineplot - 连接散点图的点

我对 sns 线图和散点图有问题。基本上我想做的是连接散点图的点以呈现连接映射点的最近线。当面对具有相同 x 轴值的点时,线图会以某种方式改变宽度。我希望线图始终保持相同的实线。

代码:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

data = {'X': [13, 13, 13, 12, 11], 'Y':[14, 11, 13, 15, 20], 'NumberOfPlanets':[2, 5, 2, 1, 2]}
cts = pd.DataFrame(data=data)

plt.figure(figsize=(10,10))
sns.scatterplot(data=cts, x='X', y='Y', size='NumberOfPlanets', sizes=(50,500), legend=False)
sns.lineplot(data=cts, x='X', y='Y',estimator='max', color='red')
plt.show()
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述

有任何想法吗?

编辑:

如果我尝试使用 pyplot 它也不起作用:代码:

plt.plot(cts['X'], cts['Y'])
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述

我需要一条线,它连接最近的点(基本上是图像一上显示的,但具有相同的实线)。

python matplotlib scatter-plot line-plot seaborn

5
推荐指数
1
解决办法
9168
查看次数