0

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?

2
  • How do you want to "label these two" if you want them in one plot? What do you mean by one plot? One set of axes, or two subfigures directly above each other? Commented May 10, 2022 at 8:17
  • I just want to have one "picture", but it should be clear which datas belongs to the color. The answer I got from you (below) is exactly what I wanted. Thanks a lot! Commented May 10, 2022 at 8:57

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is what I wanted. Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.