我在R中的雷达图表有点麻烦.即使情节很好,我也收到以下警告:
> source('~/.active-rstudio-document')
Warning message:
In `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste0(labels, :
duplicated levels in factors are deprecated
> radar
Warning messages:
1: In `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste0(labels, :
duplicated levels in factors are deprecated
2: In `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste0(labels, :
duplicated levels in factors are deprecated
Run Code Online (Sandbox Code Playgroud)
我在其他帖子中看到了同样的错误,但我真的不明白如何将答案应用到我的数据集......
这是我的数据集
MSF,C1,2
OCA,C1,6
SIOA,C1,4
CCFF,C1,4
MSF,C2,4
OCA,C2,2
SIOA,C2,6
CCFF,C2,2
MSF,C3,6
OCA,C3,6
SIOA,C3,6
CCFF,C3,6
Run Code Online (Sandbox Code Playgroud)
这是相应雷达图的代码(可能只是我定义我的数据集的第一部分是相关的,但是......这就是我丢失的地方): …
我有一个关于我的数据顺序的问题geom_bar.
这是我的数据集:
SM_P,Spotted melanosis on palm,16.2
DM_P,Diffuse melanosis on palm,78.6
SM_T,Spotted melanosis on trunk,57.3
DM_T,Diffuse melanosis on trunk,20.6
LEU_M,Leuco melanosis,17
WB_M,Whole body melanosis,8.4
SK_P,Spotted keratosis on palm,35.4
DK_P,Diffuse keratosis on palm,23.5
SK_S,Spotted keratosis on sole,66
DK_S,Diffuse keratosis on sole,52.8
CH_BRON,Dorsal keratosis,39
LIV_EN,Chronic bronchities,6
DOR,Liver enlargement,2.4
CARCI,Carcinoma,1
Run Code Online (Sandbox Code Playgroud)
我分配以下colnames:
colnames(df) <- c("abbr", "derma", "prevalence") # Assign row and column names
Run Code Online (Sandbox Code Playgroud)
然后我绘制:
ggplot(data=df, aes(x=derma, y=prevalence)) + geom_bar(stat="identity") + coord_flip()
Run Code Online (Sandbox Code Playgroud)
为什么ggplot2会随机更改数据的顺序.我希望我的数据顺序与我的一致data.frame.
任何帮助深表感谢!
我想将 Pandas DataFrame 导出到 LaTeX,并使用.千位分隔符、,小数分隔符和两位小数位。例如4.511,34
import numpy as np
import pandas as pd
df = pd.DataFrame(
np.array([[4511.34242, 4842.47565]]),
columns=['col_1', 'col_2']
)
df.to_latex('table.tex', float_format="{:0.2f}".format)
Run Code Online (Sandbox Code Playgroud)
我能实现这个目标吗?如果我将收到的代码中的 更改.为 an 。谢谢你!,ValueError: Invalid format specifier
我有一个“种子”GeoDataFrame (GDF)(RED),它包含一个 0.5 弧分的全局网格 ((180*2)*(360*2) = 259200)。每个单元格都包含一个绝对人口估计值。此外,我有一个“水蛭”GDF(绿色),其中包含大约 8250 个相邻的各种大小(分水岭)的非常规形状。
我编写了一个脚本,根据网格单元(种子 GDF)和水蛭 GDF 中的几何形状之间的重叠区域,将种群估计值分配给水蛭 GDF 中的几何形状。该脚本非常适合我的示例数据(见下文)。然而,一旦我在我的实际数据上运行它,它就非常慢。我运行了一夜,第二天早上只执行了 27% 的计算。我将不得不多次运行此脚本并且每次都等待两天,这根本不是一种选择。
在做了一些文献研究之后,我已经用for index i in df.iterrows()(或者这与“传统”python for 循环相同)替换了 (?) for 循环,但它并没有带来我所希望的性能改进。
任何建议儿子如何加快我的代码?在 12 小时内,我的脚本仅处理了约 200000 行中的约 30000 行。
我的预期输出是 column leech_df['leeched_values']。
import geopandas as gpd
import time
from datetime import datetime
from shapely.geometry import Polygon
# =============================================================================
# Geometries for testing
# =============================================================================
polys1 = gpd.GeoSeries([Polygon([(0.00,0.00), (0.00,0.25), (0.25,0.25), (0.25,0.00)]),
Polygon([(0.00,0.25), (0.00,0.50), (0.25,0.50), (0.25,0.25)]),
Polygon([(0.00,0.50), (0.00,0.75), (0.25,0.75), (0.25,0.50)]),
Polygon([(0.25,0.00), (0.25,0.25), (0.50,0.25), (0.50,0.00)]), …Run Code Online (Sandbox Code Playgroud) GeoDataFrame.plot()我正在为每个月创建一个带有 GeoPandas 子图的多重图。如何为所有子图共用图例以及 x 和 y 轴并控制图大小?
我知道有sharex=True,sharey=True但我不知道把它放在哪里。
plt.figure(sharex=True, sharey=True)回报TypeError: __init__() got an unexpected keyword argument 'sharex'
world.plot(column='pop_est', ax=ax, legend=True, sharex=True, sharey=True)回报AttributeError: 'PatchCollection' object has no property 'sharex'
ax = plt.subplot(4, 3, index + 1, sharex=True, sharey=True)回报TypeError: cannot create weak reference to 'bool' object
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
months = pd.DataFrame(["January", "February", "March", "April", "May", "June", "July", "August", …Run Code Online (Sandbox Code Playgroud) 如果我有下面的图,如何将颜色图/图例转换为对数刻度?
import geopandas as gpd
import matplotlib.pyplot as plt
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world = world[(world.pop_est>0) & (world.name!="Antarctica")]
fig, ax = plt.subplots(1, 1)
world.plot(column='pop_est', ax=ax, legend=True)
Run Code Online (Sandbox Code Playgroud)
python ×4
geopandas ×3
ggplot2 ×2
pandas ×2
r ×2
geom-bar ×1
ggproto ×1
javascript ×1
latex ×1
matplotlib ×1
node.js ×1
npm ×1
performance ×1
tabulator ×1