- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 matplotlib.plot_surface
时遇到了问题。当我重现this example时,我得到了我应该得到的,一切都很好:
但是,当我自己做某事时(绘制地球的等势 EGM96 geoid by NASA ),我会在图形上出现奇怪的面孔(蓝色区域):
生成我的图形的代码如下。我尝试更改 plot_surface
的 antialiased
和 shadow
参数,但无济于事。我已经不知道如何解决这个问题了,所以如果有人知道,甚至怀疑某些事情,我很乐意听到。
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot, matplotlib.cm, scipy.special, numpy, math
" Problem setup. "
GM = 3986004.415E8 # m**3/s**2, from EGM96.
a = 6378136.3 # m, from EGM96.
N_POINTS = 50 # Number of lattitudes and longitudes used to plot the geoid.
latitudes = numpy.linspace(0, 2*numpy.pi, N_POINTS) # Geocentric latitudes and longitudes where the geoid will be visualised.
longitudes = numpy.linspace(0, 2*numpy.pi, N_POINTS)
radius = 6378136.3 # Radius at which the equipotential will be computed, m.
MAX_DEGREE = 2 # Maximum degree of the geopotential to visualise.
" EGM96 coefficients - minimal working example. "
Ccoeffs={2:[-0.000484165371736, -1.86987635955e-10, 2.43914352398e-06]}
Scoeffs={2:[0.0, 1.19528012031e-09, -1.40016683654e-06]}
" Compute the gravitational potential at the desired locations. "
gravitationalPotentials = numpy.ones( latitudes.shape ) # Gravitational potentials computed with the given geoid. Start with ones and just add the geoid corrections.
for degree in range(2, MAX_DEGREE+1): # Go through all the desired orders and compute the geoid corrections to the sphere.
temp = 0. # Contribution to the potential from the current degree and all corresponding orders.
legendreCoeffs = scipy.special.legendre(degree) # Legendre polynomial coefficients corresponding to the current degree.
for order in range(degree): # Go through all the orders corresponding to the currently evaluated degree.
temp += legendreCoeffs[order] * numpy.sin(latitudes) * (Ccoeffs[degree][order]*numpy.cos( order*longitudes ) + Scoeffs[degree][order]*numpy.sin( order*longitudes ))
gravitationalPotentials = math.pow(a/radius, degree) * temp # Add the contribution from the current degree.
gravitationalPotentials *= GM/radius # Final correction.
" FIGURE THAT SHOWS THE SPHERICAL HARMONICS. "
fig = matplotlib.pyplot.figure(figsize=(12,8))
ax = Axes3D(fig)
ax.set_aspect("equal")
ax.view_init(elev=45., azim=45.)
ax.set_xlim([-1.5*radius, 1.5*radius])
ax.set_ylim([-1.5*radius, 1.5*radius])
ax.set_zlim([-1.5*radius, 1.5*radius])
# Make sure the shape of the potentials is the same as the points used to plot the sphere.
gravitationalPotentialsPlot = numpy.meshgrid( gravitationalPotentials, gravitationalPotentials )[0] # Don't need the second copy of colours returned by numpy.meshgrid
gravitationalPotentialsPlot /= gravitationalPotentialsPlot.max() # Normalise to [0 1]
" Plot a sphere. "
Xs = radius * numpy.outer(numpy.cos(latitudes), numpy.sin(longitudes))
Ys = radius * numpy.outer(numpy.sin(latitudes), numpy.sin(longitudes))
Zs = radius * numpy.outer(numpy.ones(latitudes.size), numpy.cos(longitudes))
equipotential = ax.plot_surface(Xs, Ys, Zs, facecolors=matplotlib.cm.jet(gravitationalPotentialsPlot), rstride=1, cstride=1, linewidth=0, antialiased=False, shade=False)
fig.show()
最佳答案
这些方程
Xs = radius * np.outer(np.cos(latitudes), np.sin(longitudes))
Ys = radius * np.outer(np.sin(latitudes), np.sin(longitudes))
Zs = radius * np.outer(np.ones(latitudes.size), np.cos(longitudes))
正在计算给定半径、纬度和经度的球坐标的笛卡尔 X、Y、Z 坐标。但如果是这样,那么经度的范围应该是 0 到 pi,而不是 0 到 2pi。因此,改变
longitudes = np.linspace(0, 2*np.pi, N_POINTS)
到
longitudes = np.linspace(0, np.pi, N_POINTS)
<小时/>
import math
import numpy as np
import scipy.special as special
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
" Problem setup. "
# m**3/s**2, from EGM96.
GM = 3986004.415E8
# m, from EGM96.
a = 6378136.3
# Number of lattitudes and longitudes used to plot the geoid.
N_POINTS = 50
# Geocentric latitudes and longitudes where the geoid will be visualised.
latitudes = np.linspace(0, 2*np.pi, N_POINTS)
longitudes = np.linspace(0, np.pi, N_POINTS)
# Radius at which the equipotential will be computed, m.
radius = 6378136.3
# Maximum degree of the geopotential to visualise.
MAX_DEGREE = 2
" EGM96 coefficients - minimal working example. "
Ccoeffs={2:[-0.000484165371736, -1.86987635955e-10, 2.43914352398e-06]}
Scoeffs={2:[0.0, 1.19528012031e-09, -1.40016683654e-06]}
" Compute the gravitational potential at the desired locations. "
# Gravitational potentials computed with the given geoid. Start with ones and
# just add the geoid corrections.
gravitationalPotentials = np.ones( latitudes.shape )
# Go through all the desired orders and compute the geoid corrections to the
# sphere.
for degree in range(2, MAX_DEGREE+1):
# Contribution to the potential from the current degree and all
# corresponding orders.
temp = 0.
# Legendre polynomial coefficients corresponding to the current degree.
legendreCoeffs = special.legendre(degree)
# Go through all the orders corresponding to the currently evaluated degree.
for order in range(degree):
temp += (legendreCoeffs[order]
* np.sin(latitudes)
* (Ccoeffs[degree][order]*np.cos( order*longitudes )
+ Scoeffs[degree][order]*np.sin( order*longitudes )))
# Add the contribution from the current degree.
gravitationalPotentials = math.pow(a/radius, degree) * temp
# Final correction.
gravitationalPotentials *= GM/radius
" FIGURE THAT SHOWS THE SPHERICAL HARMONICS. "
fig = plt.figure(figsize=(12,8))
ax = Axes3D(fig)
ax.set_aspect("equal")
ax.view_init(elev=45., azim=45.)
ax.set_xlim([-1.5*radius, 1.5*radius])
ax.set_ylim([-1.5*radius, 1.5*radius])
ax.set_zlim([-1.5*radius, 1.5*radius])
# Make sure the shape of the potentials is the same as the points used to plot
# the sphere.
# Don't need the second copy of colours returned by np.meshgrid
gravitationalPotentialsPlot = np.meshgrid(
gravitationalPotentials, gravitationalPotentials )[0]
# Normalise to [0 1]
gravitationalPotentialsPlot /= gravitationalPotentialsPlot.max()
" Plot a sphere. "
Xs = radius * np.outer(np.cos(latitudes), np.sin(longitudes))
Ys = radius * np.outer(np.sin(latitudes), np.sin(longitudes))
Zs = radius * np.outer(np.ones(latitudes.size), np.cos(longitudes))
equipotential = ax.plot_surface(
Xs, Ys, Zs, facecolors=plt.get_cmap('jet')(gravitationalPotentialsPlot),
rstride=1, cstride=1, linewidth=0, antialiased=False, shade=False)
plt.show()
产量
关于python - Matplotlibplot_surface 伪面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28787069/
如标题所示,我正在寻找有关伪/冒号 header 字段用途的一些信息,即我想知道为什么我们有第二种类型的 header 字段... 另外 - 我知道在 http2 中使用伪/冒号 header 字段代
(伪)多线程:借助外力 利用WEB服务器本身的多线程来处理,从WEB服务器多次调用我们需要实现多线程的程序。 QUOTE: 我们知道PHP本身是不支持多线程的, 但是我们的WEB服务器是支持多线程的
您如何在 HDL (verilog) 中实现硬件随机数生成器? 需要考虑哪些选项? 这个问题是在self-answer之后格式。鼓励添加答案和更新。 最佳答案 正如摩根的回答中所指出的,这只会产生一个
我写了这个CSS: div { width: 500px; height:150px; margin-left:150px; background: lightblue; } div:
这是我要解决的问题:从数据库A读取一个字符串,将该字符串转换为Date对象,将Date对象存储到数据库B中。 例)数据库A:从数据库A读入日期字符串“ 2015-03-08 02:00:00”,转换为
我想创建 std::fscanf() 的 sibling (我知道这是一个 C 函数)。所以,我的界面是这样的: template std::size_t ts_scanf(is, format,
运行 PostgreSQL 7.x(是的,我正在升级) 问题: 如果没有返回数据,我有三到四个字段需要设置。 正在考虑这样的事情 SELECT CASE WHEN default_fie
出于某种原因,我很难在 JS 中为我的游戏执行以下代码: 假设我们要求用户在棋盘上移动一个棋子。他们可以做的位置是位置A、位置B或位置C。每个位置一次只能容纳一件。否则为无效移动。 第一个用户决定
我已经毫无问题地编写了霍夫曼树的代码,但现在我希望在文件和树中添加伪 EOF,以便我知道何时停止从文件中读取。 我完全掌握了伪 EOF 的概念。我还了解到没有 ASCII 值 > 255 的字符。 我
给定一个按钮 ::after 当被触发时,伪 :after 类需要有一个类 search-active 切换,为按钮设置背景颜色 .primary .search:after, .primary
我想让第一行的文本像第二行一样缩进 (50px)。有什么办法吗?非常感谢! body{ counter-reset: h2counter; } h1{ counter-reset: h2counter
:before 或 :after 这样的伪元素是否可以从父元素的不同属性继承值? 在我的例子中,我有一个第三方组件设置其元素运行时的背景颜色...我需要继承该颜色并将其设置为伪元素的边框颜色。 最佳答
在并行循环中请求随机数总是返回相同的伪随机数。我怎样才能避免这种情况? % workers initialization: if matlabpool('size') == 0 matlabp
假设最大IP可以包含每个“点”括号中的最大数量999,即999.999.999.999 是最大的可用值。 我已经在计算器中检查了正则表达式 ([0-9]+.){3}[0-9]。那么,为什么程序抛出运行
我对随机数生成的概念非常陌生,我需要为用c编写的工作创建自己的算法(内置的随机数生成器对我不起作用)。 有人能给我介绍一个很好的主题,这样我就可以理解这个概念了吗?到目前为止,我所发现的一切似乎都是用
假设我有一个数字序列:{n, n+1, n+2, ... n+m} 在不提前存储数字的情况下,我想创建一个函数 f(),给定序列 {1,2,3,...m} 将以随机(或至少伪)的方式吐出原始集合随机)
什么是伪 tcp channel ,如何实现? 最佳答案 伪 TCP 是一种协议(protocol),它实现了 TCP 的一些思想,以通过不可靠的、基于数据包的接口(interface)提供可靠的数据
我正在尝试展开一些嵌套循环,以牺牲内存为代价(可能)获得更好的性能。在我的场景中,我最终会得到一个包含大约 3 亿个元素(元组)的列表,我必须以(或多或少)随机顺序产生这些元素。 在这个数量级上,ra
如何在 PHP 中生成(伪)随机字母数字字符串,例如:'d79jd8c'? 最佳答案 首先创建一个包含所有可能字符的字符串: $characters = 'abcdefghijklmnopqrstu
我有一段代码可以为玩家生成迷你任务。这很简单,要获得两个不同的点(起点和终点),我有一个如下所示的算法: std::vector missions; missions.push_bac
我是一名优秀的程序员,十分优秀!