网格线未显示 [英] Gridlines not showing up

查看:130
本文介绍了网格线未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了以下代码,以读取.graphml文件,进行计算(特征值),然后绘制结果.这是到目前为止的代码:

I've set up the following code to read in a .graphml file, preform a calculation (eigenvalues) and then plot the results. Here is the code I have so far:

import numpy as np
import networkx as nx
import matplotlib.pyplot as plt

# Read in the Data

G = nx.read_graphml("/home/user/DropBox_External_Datasets/JHU_Human_Brain/cat_brain_1.graphml")

nx.draw(G)
plt.savefig("test_graph.png")

Z = nx.to_numpy_matrix(G)

# Get Eigenvalues and Eigenvectors
# ----------------------------------------------------------------------------------
#
e_vals, e_vec = np.linalg.eigh(Z)

print("The eigenvalues of A are:", e_vals)
print("The size of the eigenvalues matrix is:", e_vals.shape)
# ----------------------------------------------------------------------------------

plt.plot(e_vals, 'g^')
plt.ylabel('Eigenvalues')
# plt.axis([-30, 300, -15, 30]) # Optimal settings for Rhesus data
# plt.axis([-0.07, 1, -0.2, 1.2])  # range to zoom in on cluster of points in Rhesus data

plt.grid(b=True, which='major', color='b', linestyle='-')
plt.show()

但是图形上没有显示网格线或轴.除了plt.grid()之外,还有其他需要使用的东西吗?

But no gridlines or axes show up on the graph. Is there something other then plt.grid() that I need to use?

推荐答案

这可能有所帮助-我发现远离常规pyplot命令是使事情按预期工作的更可靠的方法. Pyplot本质上是面向对象调用的一个大包装.我写的东西应该是等​​效的:

This may help - I have been finding that moving away from general pyplot commands is a more robust way to make things work as expected. Pyplot is essentially a big wrapper for the object-oriented calls. I've written something that should be equivalent:

import matplotlib.pyplot as plt

# ... your other code here

fig, ax = plt.subplots(ncols=1, nrows=1) # These arguments can be omitted for one
                                         # plot, I just include them for clarity
ax.plot(e_vals, 'g^')
ax.set_ylabel('Eigenvalues')

ax.grid(b=True, which='major', color='b', linestyle='-')

plt.show()

这篇关于网格线未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆