sbh*_*hdp 5 python plot data-visualization matplotlib seaborn
我做了一个看起来像这样的情节
我想关闭沿 y 轴的刻度标签。要做到这一点,我正在使用
plt.tick_params(labelleft=False, left=False)
Run Code Online (Sandbox Code Playgroud)
关闭比例1e67会使情节看起来更好。我怎么做?
Tre*_*ney 25
seaborn用于绘制绘图,但它只是matplotlib.
matplotlib方法。.set()..set(yticklabels=[])应该删除刻度标签。
.set_title(),但您可以使用.set(title='').set(ylabel=None)应删除轴标签。.tick_params(left=False)将去除蜱虫。python 3.11, pandas 1.5.2, matplotlib 3.6.2,seaborn 0.12.1import seaborn as sns
import matplotlib.pyplot as plt
# load data
exercise = sns.load_dataset('exercise')
pen = sns.load_dataset('penguins')
# create figures
fig, ax = plt.subplots(2, 1, figsize=(8, 8))
# plot data
g1 = sns.boxplot(x='time', y='pulse', hue='kind', data=exercise, ax=ax[0])
g2 = sns.boxplot(x='species', y='body_mass_g', hue='sex', data=pen, ax=ax[1])
plt.show()
Run Code Online (Sandbox Code Playgroud)
fig, ax = plt.subplots(2, 1, figsize=(8, 8))
g1 = sns.boxplot(x='time', y='pulse', hue='kind', data=exercise, ax=ax[0])
g1.set(yticklabels=[]) # remove the tick labels
g1.set(title='Exercise: Pulse by Time for Exercise Type') # add a title
g1.set(ylabel=None) # remove the axis label
g2 = sns.boxplot(x='species', y='body_mass_g', hue='sex', data=pen, ax=ax[1])
g2.set(yticklabels=[])
g2.set(title='Penguins: Body Mass by Species for Gender')
g2.set(ylabel=None) # remove the y-axis label
g2.tick_params(left=False) # remove the ticks
plt.tight_layout()
plt.show()
Run Code Online (Sandbox Code Playgroud)
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# sinusoidal sample data
sample_length = range(1, 1+1) # number of columns of frequencies
rads = np.arange(0, 2*np.pi, 0.01)
data = np.array([(np.cos(t*rads)*10**67) + 3*10**67 for t in sample_length])
df = pd.DataFrame(data.T, index=pd.Series(rads.tolist(), name='radians'), columns=[f'freq: {i}x' for i in sample_length])
df.reset_index(inplace=True)
# plot
fig, ax = plt.subplots(figsize=(8, 8))
ax.plot('radians', 'freq: 1x', data=df)
# or skip the previous two lines and plot df directly
# ax = df.plot(x='radians', y='freq: 1x', figsize=(8, 8), legend=False)
Run Code Online (Sandbox Code Playgroud)
# plot
fig, ax = plt.subplots(figsize=(8, 8))
ax.plot('radians', 'freq: 1x', data=df)
# or skip the previous two lines and plot df directly
# ax = df.plot(x='radians', y='freq: 1x', figsize=(8, 8), legend=False)
ax.set(yticklabels=[]) # remove the tick labels
ax.tick_params(left=False) # remove the ticks
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5663 次 |
| 最近记录: |