I am plotting a range of frequencies and the values start at 800 and go up to 10k. While using the code below, I am very puzzled why the log scale start from 1 on the x-axis.. it needs to start at 10^3.
fig, ax = plt.subplots(figsize=(10, 8))
g = sns.pointplot(data=combined_data, x="freq", y="signal", linestyles=["-"], color="hotpink", markers=["s"])
g.set(xscale='log')
g.set(yscale='log')
plt.axvline(20, linestyle='--', color='steelblue')
plt.xlabel("Frequency [Hz] ---> ")
plt.ylabel("Signal [mV] ---> ")
CodePudding user response:
You need to create a sns.lineplot
. sns.pointplot
makes the x-axis categorical, so internally numbered 0,1,2,...
also for numeric data. This is easier to see when the x-axis wouldn't be set in log scale yet.
The following code illustrates the difference:
from matplotlib import pyplot as plt
import seaborn as sns
import numpy as np
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(16, 5))
x = np.logspace(1, 4, 40)
y=1000 - np.sqrt(x)
sns.pointplot(x=x, y=y, linestyles=["-"], color="hotpink", markers=["s"], ax=ax1)
ax1.set(xscale='log', yscale='log')
ax1.axvline(20, linestyle='--', color='steelblue')
ax1.set_title('sns.pointplot()')
sns.lineplot(x=x, y=y, color="hotpink", marker="s", markersize=10, ax=ax2)
ax2.set(xscale='log', yscale='log')
ax2.set_title('sns.lineplot()')
for ax in (ax1, ax2):
ax.axvline(20, linestyle='--', color='steelblue')
ax.set_xlabel("Frequency [Hz] ---> ")
ax.set_ylabel("Signal [mV] ---> ")
plt.tight_layout()
plt.show()