- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个笔记本 ( github link ),我在其中使用 geopandas 绘制带有不同国家/地区颜色的 map 。根据绘图的顺序,有时它不符合我指定的 figsize() 。我在 Ubuntu 20.04 和 Firefox 中本地运行的 jupyter 中以及在 Chromium 中运行的 Binder 和 Colab 中重复看到这种行为。
有人可以帮助我了解发生了什么吗?这是错误还是我对 geopandas/matplotlib 的控制有误?
import matplotlib.pyplot as plt
import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
sixc = world[ world['continent'] != 'Antarctica' ]
asia = world[ world['continent'] == 'Asia' ]
noam = world[ world['continent'] == 'North America']
swed = world[ world['iso_a3'] == 'SWE' ]
# This works, makes a 2x1 landscapey aspect
axes = sixc.plot(figsize=(8,4), color='lightgrey')
asia.plot(ax=axes, color='green')
noam.plot(ax=axes, color='purple')
# Plotting swed at the end breaks figsize, makes it squareish
axes = sixc.plot(figsize=(8,4), color='lightgrey')
asia.plot(ax=axes, color='green')
noam.plot(ax=axes, color='purple')
swed.plot(ax=axes, color='yellow')
# Plotting swed in the middle makes it ok again
axes = sixc.plot(figsize=(8,4), color='lightgrey')
asia.plot(ax=axes, color='green')
swed.plot(ax=axes, color='yellow')
noam.plot(ax=axes, color='purple')
(此外,对于我的一些(但不是全部!)学生来说,那个 splinter 的情节也没有浅灰色背景国家。这可能是导致方面问题的任何结果/副作用吗?)
最佳答案
对于您使用的 geopandas
v 0.8.1,您使用的绘图命令的默认
纵横比是自动
。因此,您获得的输出图将具有不可预测的纵横比值。尝试
print(axes.get_aspect())
对于每个地 block 。在以前版本的 geopandas 中,将得到 equal
作为输出,并且绘图是正确的。但在您的情况下,您将获得不代表相等方面的值。
为了简单地解决您的问题,您可以添加这行代码:
axes.set_aspect('equal')
在最后一个情节陈述之后。
关于python - Jupyter/Geopandas 绘图顺序打破了 figsize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65636715/
我正在尝试保存一张大图片(实际上比我的显示器的分辨率大),但是在增加 figsize 时我得到了相同大小的 png 图片。因此,对于下面的两个示例,我得到了完全相同的文件: import matplo
这个问题已经有答案了: Displaying exactly the figure that will be saved (2 个回答) 已关闭 5 年前。 我想用 matplotlib 绘制一个正方
这个问题已经有答案了: Displaying exactly the figure that will be saved (2 个回答) 已关闭 5 年前。 我想用 matplotlib 绘制一个正方
我正在尝试创建带有一些标记的水平框(轴)。 尽管 y 轴按比例调整(即,高度变量使用 figsize 比率来计算适当的 y 最大值),但一切正常,除了轴的大小会随着 x 轴的不同范围而变化。 mini
这个问题在这里已经有了答案: How to change the figure size of a seaborn axes or figure level plot (13 个答案) 关闭 5 年
我不明白为什么要取消注释以下代码的第 3 行 from matplotlib import pyplot pyplot.clf() #pyplot.figure(figsize=(400, 200))
我是 pandas 的新手,用于数据分析,我刚刚安装了具有所需依赖项(NumPy、python-dateutil、pytz、numexpr、bottleneck 和 matplotlib)的 pand
我有一个笔记本 ( github link ),我在其中使用 geopandas 绘制带有不同国家/地区颜色的 map 。根据绘图的顺序,有时它不符合我指定的 figsize() 。我在 Ubuntu
这个问题在这里已经有了答案: How to plot non-square Seaborn jointplot or JointGrid (3 个回答) 2年前关闭。 我正在使用 Jupyter No
我正在使用 MathTextParser 来描述 Qt 中的一些方程式。因此,我从 dict 中获取所需的 tex 字符串,使用我创建的解析器的 to_rgba 方法解析它(移交一般字体大小和 dpi
在 Pandas 教程中,他们使用 http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/v0.1/cookbook/Chapter
我正在使用 matplotlib 绘制一些图形。通常,标准做法是从图形的尺寸开始并指定轴的尺寸,以便图形随后缩放到可用空间。 但是我有一个请求来扩展图表的高度以容纳 y 轴上的异常数据。 我知道我可以
我有几个不同的条形图图形可以生成不同数量的条形图。因此,图形的总宽度和高度各不相同,但我希望所有条形图的条形大小始终相同。 到目前为止,我尝试的是根据条数按比例调整图形大小。这似乎并不一致。 这是一个
我希望使用以下代码调整子图的大小,使生成的 PDF 宽度为 5 英寸,高度为 8 英寸。但无论我在 figsize 位中放入什么,生成的文件都是 8 英寸宽和 6 英寸高。我做错了什么? import
我有一个在鸢尾花数据集上训练的决策树的 GraphViz 表示。 import graphviz dot_data = tree.export_graphviz(clf, out_file=None,
这个问题在这里已经有了答案: How do I change the size of figures drawn with Matplotlib? (21 个回答) 关闭 4 年前。 如您所见,代码
如何在 seaborn 中更改 lmplot 的图形大小? 这是我当前的代码,但显然 figsize 不被接受。 sns.lmplot(x="x", y="y", hue="category", da
我正在尝试使用 for 循环将多个图形绘制成 1 个,但我遇到了这个问题。我在其他循环中尝试过它,它工作得很好,但我不知道这个循环发生了什么。 使用的文件是过去 2 年欧元对美元的汇率,我试图在图表上
我想创建一个具有指定图形大小的图,其中 3D 轴尝试使用整个可用空间,同时在所有轴上保持相等的纵横比。 我目前的尝试显示了一个隐藏了部分网格的剪切矩形。 from mpl_toolkits.mplot
我画了2张图,这是截图 figsize 顶部的(2D)按预期渲染。底部那个(3D)不是,图太小了! 设置figsize的值不起作用。 figsize=(3,3) 和Figsize=(13,13) 给出
我是一名优秀的程序员,十分优秀!