matplotlib -Pandas-如何在一个图中创建多标签?

发布于 2025-01-27 10:24:01 字数 788 浏览 1 评论 0原文

这是我的代码:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from numpy.random import randn

df = pd.read_csv(r"XXXXXXX.txt")

df.plot(x='qPkw', y='vPkw', kind='scatter', figsize=(12, 12), use_index=True,
        title="q-v-Diagram (Pkw)", xticks=[0, 25, 50, 75, 100, 125], yticks=[0, 100, 200, 300, 400, 500],
        xlabel="v-Pkw", ylabel="q-Pkw", fontsize=15, color="black", label="Pkw")

df.plot(x='qLkw', y='vLkw', kind = 'scatter', figsize=(12, 12), use_index=True,
        title="q-v-Diagram (Lkw)", xticks=[0, 5, 10, 15, 20, 25, 30], yticks=[0, 100, 200, 300, 400],
        xlabel="v-Lkw", ylabel="q-Lkw", fontsize= 15, color="blue", label="Lkw")

plt.show()

而不是一个,我得到了两个图。

我只想将这两个图中的这两个图。 我也想标记这两个。

有人看到错误吗?

This is my code:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from numpy.random import randn

df = pd.read_csv(r"XXXXXXX.txt")

df.plot(x='qPkw', y='vPkw', kind='scatter', figsize=(12, 12), use_index=True,
        title="q-v-Diagram (Pkw)", xticks=[0, 25, 50, 75, 100, 125], yticks=[0, 100, 200, 300, 400, 500],
        xlabel="v-Pkw", ylabel="q-Pkw", fontsize=15, color="black", label="Pkw")

df.plot(x='qLkw', y='vLkw', kind = 'scatter', figsize=(12, 12), use_index=True,
        title="q-v-Diagram (Lkw)", xticks=[0, 5, 10, 15, 20, 25, 30], yticks=[0, 100, 200, 300, 400],
        xlabel="v-Lkw", ylabel="q-Lkw", fontsize= 15, color="blue", label="Lkw")

plt.show()

Instead of one, I get two plots.

I just want to have these two in one plot.
Also I want to label these two.

Someone sees the mistake?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小情绪 2025-02-03 10:24:01

捕获第一个轴,并在第二个轴上使用ax关键字。

ax = df.plot(x='qPkw', y='vPkw', kind='scatter', figsize=(12, 12), use_index=True,
        title="q-v-Diagram (Pkw)", xticks=[0, 25, 50, 75, 100, 125], yticks=[0, 100, 200, 300, 400, 500],
        xlabel="v-Pkw", ylabel="q-Pkw", fontsize=15, color="black", label="Pkw")

df.plot(x='qLkw', y='vLkw', kind = 'scatter', figsize=(12, 12), use_index=True,
        title="q-v-Diagram (Lkw)", xticks=[0, 5, 10, 15, 20, 25, 30], yticks=[0, 100, 200, 300, 400],
        xlabel="v-Lkw", ylabel="q-Lkw", fontsize= 15, color="blue", label="Lkw", 
        ax=ax)

请注意,将忽略第一个Xticks和Yticks设置。 Xlabel和Ylabel也是如此。这是一个数字,因为它是一个数字。

Capture the first axis, and use the ax keyword in the second plot with the first axis.

ax = df.plot(x='qPkw', y='vPkw', kind='scatter', figsize=(12, 12), use_index=True,
        title="q-v-Diagram (Pkw)", xticks=[0, 25, 50, 75, 100, 125], yticks=[0, 100, 200, 300, 400, 500],
        xlabel="v-Pkw", ylabel="q-Pkw", fontsize=15, color="black", label="Pkw")

df.plot(x='qLkw', y='vLkw', kind = 'scatter', figsize=(12, 12), use_index=True,
        title="q-v-Diagram (Lkw)", xticks=[0, 5, 10, 15, 20, 25, 30], yticks=[0, 100, 200, 300, 400],
        xlabel="v-Lkw", ylabel="q-Lkw", fontsize= 15, color="blue", label="Lkw", 
        ax=ax)

Be aware that the first xticks and yticks settings will be ignored. The same for the xlabel and ylabel. That has to be, since it is in one figure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文