小编Gau*_*ain的帖子

在python matplotlib中连接具有相同值的点

我试图绘制一个numpy数组,使得所有具有相同y轴值的点应该在一条直线上连接.但有些我无法实现这一目标.

import numpy as np
import matplotlib as mp
import matplotlib.pyplot as plt

# Declare numpy array with nans
x=np.array([np.nan,10005,10005,10006,10006,10006,10007,10007,10007, 10008,10007,10008,10008,10008, np.nan,10010,10010,10010, np.nan, np.nan, np.nan, np.nan])

# Plot the points
plt.plot(x, marker="o", linestyle='-')

# Display the plot in the window
plt.show()
Run Code Online (Sandbox Code Playgroud)

这导致: 在此输入图像描述

但我希望情节如下:

在此输入图像描述

此外,如果有一种方法可以在图的顶部和底部添加一些边距,以清楚地显示边界点.

python numpy matplotlib

6
推荐指数
1
解决办法
1576
查看次数

子图中的 Seaborn clustermap

我正在尝试将数据框的集群图和箱线图绘制为子图。我无法将 clustermap 绘制为子图,因为它是图形级别的图。有没有办法实现这一目标?

import pandas as pd
import seaborn as sns

# initiliaze a dataframe with index and column names
idf = pd.DataFrame.from_items([('A', [1, 2, 3]), 
                               ('B', [4, 5, 6]), 
                               ('C', [10, 20, 30]), 
                               ('D', [14, 15, 16])], 
                               orient='index', columns=['x', 'y','z'])

# Get the figure and two subplots, unpack the axes array immediately
fig, (ax1, ax2) = plt.subplots(2, sharex=True)

# Plot a boxplot in one of the subplot
idf.plot(kind='box', ax=ax1)

# Plot the clustermap in the other subplot
cax = …
Run Code Online (Sandbox Code Playgroud)

python matplotlib heatmap seaborn

5
推荐指数
1
解决办法
3357
查看次数

标签 统计

matplotlib ×2

python ×2

heatmap ×1

numpy ×1

seaborn ×1