Pro*_*Nag 1 python matplotlib bar-chart pandas seaborn
我需要在直方图中绘制 3 个值。与其他值相比,其中一个值非常大。当我尝试绘制它们时,由于较大的另外两个值没有显示在图中。除了 Python 中的直方图之外,还有什么方法可以用图表来说明它们吗?是否有任何缩放技巧来解决这个问题?
下面给出的代码是我试过的。我使用 python 库 numpy 和 matplotlib 来绘制图形。
import numpy as np
import matplotlib.pyplot as plt
height = [0.422602, 0.000011, 0.000453]
bars = ('2X2', '4X4', '8X8')
y_pos = np.arange(len(bars))
plt.bar(y_pos, height, color = (0.572549,0.2862,0.0,1))
plt.xlabel('Matrix Dimensions')
plt.ylabel('Fidelity for Matrices with Sparsity 1')
plt.xticks(y_pos, bars)
plt.show()
Run Code Online (Sandbox Code Playgroud)
输出是上面包含的图片。此图未描绘其他两列的值。我怎么解决这个问题?
matplotlib.pyplot.yscale('log')
或matplotlib.axes.Axes.set_yscale('log')
plt.yscale('log')
或者 ax.set_yscale('log')
'symlog'
如果有负值。matplotlib.axes.Axes.set
ax.set(yscale='log')
matplotlib
、seaborn
轴级别图和pandas
图相关。import matplotlib.pyplot as plt
import numpy as np
height = [0.422602, 0.000011, 0.000453]
bars = ('2X2', '4X4', '8X8')
y_pos = np.arange(len(bars))
Run Code Online (Sandbox Code Playgroud)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 3))
ax1.bar(y_pos, height, color = (0.572549,0.2862,0.0,1))
ax1.set(xlabel='Matrix Dimensions', ylabel='Fidelity for Matrices with Sparsity 1', title='y without log scale')
ax1.set_xticks(y_pos)
ax1.set_xticklabels(bars)
ax2.bar(y_pos, height, color = (0.572549,0.2862,0.0,1))
# set yscale; can also use plt.yscale('log') or plt.yscale('symlog')
ax2.set(yscale='log', xlabel='Matrix Dimensions', ylabel='Fidelity for Matrices with Sparsity 1', title='y with log scale')
ax2.set_xticks(y_pos)
ax2.set_xticklabels(bars)
fig.tight_layout()
plt.show()
Run Code Online (Sandbox Code Playgroud)
plt.bar(y_pos, height, color = (0.572549,0.2862,0.0,1))
plt.yscale('log')
plt.xlabel('Matrix Dimensions')
plt.ylabel('Fidelity for Matrices with Sparsity 1')
plt.xticks(y_pos, bars)
plt.show()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2670 次 |
最近记录: |