Wie extrahiert man die (großen/kleineren) Zecken aus einem Meeresgrundstück?Python

Python-Programme
Guest
 Wie extrahiert man die (großen/kleineren) Zecken aus einem Meeresgrundstück?

Post by Guest »

Ich versuche, Ticks aus meinem mit Seaborn gezeichneten Python-Plot zu extrahieren.
Ich habe zwei Codesätze unten, von denen ich dachte, dass sie zu denselben Ergebnissen führen würden. Allerdings extrahiert einer die Ticks korrekt und der andere gibt nur Nullen zurück.

Code: Select all

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()

ax = fig.gca()

t = np.arange(0.0, 100.0, 0.1)
s = np.sin(0.1 * np.pi * t) * np.exp(-t * 0.01)

ax.plot(t, s)

plt.show()

print([p.label.get_position()[0] for p in ax.xaxis.get_major_ticks()])
print([p.label.get_position()[0] for p in ax.xaxis.get_minor_ticks()])
print([p.label.get_position()[1] for p in ax.yaxis.get_major_ticks()])
print([p.label.get_position()[1] for p in ax.yaxis.get_minor_ticks()])
Ausgabe:

Code: Select all

[-20.0, 0.0, 20.0, 40.0, 60.0, 80.0, 100.0, 120.0]
[]
[-1.0, -0.75, -0.5, -0.25, 0.0, 0.25, 0.5, 0.75, 1.0, 1.25]
[]
Der andere Teil des Codes ist mit Seaborn:

Code: Select all

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd

fig = plt.figure()

ax = fig.gca()
t = np.arange(0.0, 100.0, 0.1)
s = np.sin(0.1 * np.pi * t) * np.exp(-t * 0.01)

data = pd.DataFrame()
data['x'] = t
data['y'] = s
display(data)

sns_plot = sns.scatterplot(x='x', y='y', data=data, ax=ax)
sns_plot.set_title("test plot")

print([p.label.get_position()[0] for p in ax.xaxis.get_major_ticks()])
print([p.label.get_position()[0] for p in ax.xaxis.get_minor_ticks()])
print([p.label.get_position()[1] for p in ax.yaxis.get_major_ticks()])
print([p.label.get_position()[1] for p in ax.yaxis.get_minor_ticks()])
Ausgabe:

Code: Select all

[0, 0, 0, 0, 0, 0, 0, 0]
[]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[]
Kann mir jemand zeigen, wie ich die Tick-Beschriftungen aus meinem Seaborn-Plot extrahieren kann?
Oder kann mir jemand zeigen, was im zweiten Codeblock falsch ist?
Danke!

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post