python-3.x - 在 matplotlib 中更改插图的网格属性
问题描述
这是我在此处发布的问题的后续行动。在 matplotlib 图中添加了一个网络图作为插图。
import networkx as nx
import matplotlib.pyplot as plt
G = nx.gnm_random_graph(n=10, m=15, seed=1)
nxpos = nx.spring_layout(G, dim=3, seed=1)
nxpts = [nxpos[pt] for pt in sorted(nxpos)]
nx_lines = [(nxpts[i], nxpts[j]) for i, j in G.edges()]
# node values
values = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[30, 80, 10, 79, 70, 60, 75, 78, 65, 10],
[1, .30, .10, .79, .70, .60, .75, .78, .65, .90]]
time = [0.0, 0.1, 0.2] # in seconds
fig, ax = plt.subplots()
ax.plot(
[1, 2, 3], [1, 2, 3],
'go-',
label='line 1',
linewidth=2
)
from mpl_toolkits.mplot3d import (Axes3D)
from matplotlib.transforms import Bbox
rect = [.6, 0, .5, .5]
bbox = Bbox.from_bounds(*rect)
inax = fig.add_axes(bbox, projection = '3d')
# inax.axis('off')
# set angle
angle = 25
inax.view_init(10, angle)
# hide axes, make transparent
# inax.set_facecolor('none')
inax.grid('off')
import numpy as np
# plot 3d
seen = set()
for i, j in G.edges():
x = np.stack((nxpos[i], nxpos[j]))
inax.plot(*x.T, color = 'k')
if i not in seen:
inax.scatter(*x[0], color = 'skyblue')
seen.add(i)
if j not in seen:
inax.scatter(*x[1], color = "skyblue")
seen.add(j)
fig.show()
我想更改网格属性,即将网格颜色设置为red
并更改线宽。我试过inax.grid('on', color='r')
了,但这不会改变颜色。有关如何更改设置的建议将非常有帮助。
解决方案
推荐阅读
- c - 将 printf 用于 char 时仅输出点
- html - css中的图像和文本重叠,仅在图像上链接
- javascript - 向下滚动页面时从本地存储加载更多内容
- docker - 在 jwilder/nginx-proxy Docker 容器中重写 URL
- android - 通过 android studio 录制机器人脚本时,Android 应用程序在启动画面上冻结
- sql - 具有一对多关系的 SQL(三个表)
- vhdl - VHDL 不关心自定义类型
- java - 在不干扰其他应用程序的情况下使用服务检测手势
- javascript - Laravel第二个js文件
- mysql - 与 SSL 的 mysql jdbc 连接在 tls 握手级别失败