English 中文(简体)
• 如何从一片土地上拆除或藏匿“油轮”。
原标题:How to remove or hide y-axis ticklabels from a plot

我的阴谋就是这样。

“entergraph

我想从轴线上 turn起。 而且,我利用的是这样做。

plt.tick_params(labelleft=False, left=False)

And now the plot looks like this. Even though the labels are turned off the scale 1e67 still remains. enter image description here

替换<代码>1e67 这将使这块地貌更好。 我如何这样做?

最佳回答
  • seaborn is used to draw the plot, but it s just a high-level API for matplotlib.
    • The functions called to remove the y-axis labels and ticks are matplotlib methods.
  • After creating the plot, use .set().
  • .set(yticklabels=[]) should remove tick labels.
    • This doesn t work if you use .set_title(), but you can use .set(title= )
    • Do not use sns.boxplot(...).set(xticklabels=[]) because, while this works, the object type is changed from matplotlib.axes._axes.Axes for sns.boxplot(...), to list.
  • .set(ylabel=None) should remove the axis label.
  • .tick_params(left=False) will remove the ticks.
  • Similarly, for the x-axis: How to remove or hide x-axis labels from a seaborn / matplotlib plot?
  • Tested in python 3.11, pandas 1.5.2, matplotlib 3.6.2, seaborn 0.12.1

Example 1

import 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()

“enterography

Remove Labels

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()

“entergraph

Example 2

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)

“entergraph

Remove Labels

# 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

“entergraph

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签