【问题标题】:How could I get the desired matplotlib 3d plot style?如何获得所需的 matplotlib 3d 绘图样式?
【发布时间】:2018-04-06 05:41:54
【问题描述】:

我从 here 复制了一个 sn-p 并运行它,但没有得到所需的样式。

复制代码

#!/usr/bin/evn python

import numpy as np
import scipy.linalg
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

# some 3-dim points
mean = np.array([0.0, 0.0, 0.0])
cov = np.array([[1.0, -0.5, 0.8], [-0.5, 1.1, 0.0], [0.8, 0.0, 1.0]])
data = np.random.multivariate_normal(mean, cov, 50)

# regular grid covering the domain of the data
X, Y = np.meshgrid(np.arange(-3.0, 3.0, 0.5), np.arange(-3.0, 3.0, 0.5))
XX = X.flatten()
YY = Y.flatten()

order = 1  # 1: linear, 2: quadratic
if order == 1:
    # best-fit linear plane
    A = np.c_[data[:, 0], data[:, 1], np.ones(data.shape[0])]
    C, _, _, _ = scipy.linalg.lstsq(A, data[:, 2])  # coefficients

    # evaluate it on grid
    Z = C[0] * X + C[1] * Y + C[2]

    # or expressed using matrix/vector product
    #Z = np.dot(np.c_[XX, YY, np.ones(XX.shape)], C).reshape(X.shape)

elif order == 2:
    # best-fit quadratic curve
    A = np.c_[np.ones(data.shape[0]), data[:, :2],
              np.prod(data[:, :2], axis=1), data[:, :2]**2]
    C, _, _, _ = scipy.linalg.lstsq(A, data[:, 2])

    # evaluate it on a grid
    Z = np.dot(np.c_[np.ones(XX.shape), XX, YY, XX * YY, XX**2, YY**2],
               C).reshape(X.shape)

# plot points and fitted surface
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, alpha=0.2)
ax.scatter(data[:, 0], data[:, 1], data[:, 2], c='r', s=50)
plt.xlabel('X')
plt.ylabel('Y')
ax.set_zlabel('Z')
ax.axis('equal')
ax.axis('tight')
plt.show()

实际结果

看到这个link

预期结果

看到这个link

这两种风格有很大的不同:网格颜色、线框、表面颜色等。这个图片的风格是不是matplotlib以前的版本?如果是这样,我怎么能得到那种风格?

Matplotlib 版本

  • 操作系统:Linux Mint 18.3
  • Matplotlib 版本:2.2.2
  • Matplotlib 后端:Qt4Agg
  • Python 版本:2.7.12

我在虚拟环境中通过 pip 安装了 matplotlib。

【问题讨论】:

  • 回到绘图板;访问图库、文档、示例..??
  • 如果可能,您应该切换到 Python 3.6+。 pythonclock.org
  • 感谢@wwii 我尝试了 3.6.5,但仍然无法获得所需的样式。有什么想法吗?
  • 在 Python 3.5 中,matplotlib 2.2.2 plt.style.use('classic') 工作
  • 谢谢! @f5r5e5d 它有效!我不知道 3d 绘图也可以使用样式。好像有些款式不行?另外,你能把你的评论变成答案吗?

标签: python matplotlib


【解决方案1】:

在我的 Python 3.5 中,matplotlib 2.2.2 安装 plt.style.use('classic') 似乎可以工作

Why matplotlib graphs and icons look different on two computers with the same OS? 类似,但 Q 是关于图标的

【讨论】:

    猜你喜欢
    • 2020-12-02
    • 1970-01-01
    • 1970-01-01
    • 2021-03-08
    • 1970-01-01
    • 2021-05-12
    • 2014-06-28
    • 1970-01-01
    相关资源
    最近更新 更多