Issue
I want to create a scatter plot without x or y ticks. But I would like to see the plot in whitegrid style. When I explicitly sets the xticks, I lose the whitegrids too. Any tricks ?
import matplotlib.pyplot as plt
plt.style.use('ggplot')
import numpy as np
fig, ax = plt.subplots(frameon=False)
colormap = np.array(["orange","cyan"])
x = np.array([2,2,2,4,4,4,4]*10)
y = np.array([2,4])
col = np.array(['b','g'])
colors = colormap[np.where(y==x[:,None])[1]]
Y = np.random.random((70,2))
plt.xticks([])
plt.yticks([])
ax.scatter(Y[:,0], Y[:,1], c=colors)
Solution
Below is the example you can refer as suggested by Mr T, you can make xticks
font color to background color.
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sns.set_style("whitegrid")
fig, ax = plt.subplots(frameon=False)
colormap = np.array(["orange","cyan"])
x = np.array([2,2,2,4,4,4,4]*10)
y = np.array([2,4])
col = np.array(['b','g'])
colors = colormap[np.where(y==x[:,None])[1]]
Y = np.random.random((70,2))
ax.scatter(Y[:,0], Y[:,1], c=colors)
ax.tick_params(axis="both", colors="white") #suggested by Mr T, easier way
# plt.setp(ax.get_xticklabels(),color="white", backgroundcolor="white") # suggested by Me
# plt.setp(ax.get_yticklabels(),color="white", backgroundcolor="white") # suggested by Me
I have adopted Mr T's answer which is easier and less complicated.
Answered By - Jay Patel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.