This question already has an answer here:
Matplotlib: setting x-limits also forces tick labels?
(1 answer)
Closed 5 years ago.
I can't quite figure out how to ask my question properly.
I am trying to set custom x,y ticks on a log-log plot.
Following the answer here I did,
fig1, ax1 = plt.subplots()
ax1.plot([10, 100, 1000], [1,2,3])
ax1.set_xscale('log')
ax1.set_yscale('log')
ax1.set_xticks([20, 200, 500])
ax1.set_yticks([1, 2,3])
ax1.get_xaxis().set_major_formatter
(matplotlib.ticker.ScalarFormatter())
ax1.get_yaxis().set_major_formatter
(matplotlib.ticker.ScalarFormatter())
This results in an overlapping ticklabels on of the axis.
Does anyone knows why is this happening?
This is the relevant github issue :
https://github.com/matplotlib/matplotlib/issues/8386
Quick Solution:
ax.yaxis.set_major_formatter
(matplotlib.ticker.ScalarFormatter())
ax.yaxis.set_minor_formatter
(matplotlib.ticker.NullFormatter())
Related
This question already has answers here:
Rotate tick labels in subplot (Pyplot, Matplotlib, gridspec)
(3 answers)
Closed 2 years ago.
I'm trying to plot a lot a data points and the X axis is timestamps. My problem is that for some length Matplotlib automatically squeezes them together and you cannot read the x axis, as shown in the pic:
How can I prevent this from happening? I'm trying to save that plot automatically with savefig(). It is saved to a PNG.
you can specify the X-Ticks with following:
import matplotlib.pyplot as plt
plt.plot(x_values, y_value)
plt.xticks([0,5,10])
The Plot will have less ticks.
WIthout the x-ticks:
With x-ticks:
I found the answer here on the matplotlib site:
https://matplotlib.org/3.1.1/gallery/recipes/common_date_problems.html
fig, ax = plt.subplots()
ax.plot(date, r.close)
# rotate and align the tick labels so they look better
fig.autofmt_xdate()
# use a more precise date string for the x axis locations in the
# toolbar
ax.fmt_xdata = mdates.DateFormatter('%Y-%m-%d')
ax.set_title('fig.autofmt_xdate fixes the labels')
This question already has answers here:
How to plot non-square Seaborn jointplot or JointGrid
(3 answers)
Closed 3 years ago.
I am using Jupyter Notebook and want a full width jointplot figure.
I cant seem to get it working though.
g = sns.jointplot(x="pos", y="diff", data=plot_data)
plt.figure(figsize=(16, 6))
doesn't change the size at all.
fig, ax = plt.subplots(figsize=(16, 6))
g = sns.jointplot(ax=ax, x="pos", y="diff", data=plot_data)
Throws an error.
Use the height parameter in the jointplot function to set the size of the figure(it will be square). Refer to official docs: seaborn.pydata.org/generated/seaborn.jointplot.html
This question already has answers here:
matplotlib colorbar in each subplot
(5 answers)
Closed 3 years ago.
I am creating a (10,7) subplot of multiple different gridded fields. The following code is what is being currently used:
fig, axes = plt.subplots(nrows=10, ncols=7, figsize=(18, 16), dpi= 100,
facecolor='w', edgecolor='k')
titles = ['Z1','Z2','Z3','ZDR1','ZDR2','ZDR3','Dist']
for i in range(0,10):
z = 1*10+i
for j in range(0,7):
aa = axes[i,j].matshow(alldata_sim[z,:,:,j], cmap='jet')
fig.colorbar(aa)
axes[0,j].set_title(titles[j])
axes[i,j].get_xaxis().set_visible(False)
axes[i,j].get_yaxis().set_ticks([])
axes[i,0].set_ylabel(allgauge_sim[z])
Which produces the following figure:
Figure1
The question is: how do I get the colorbars to be on the right-hand side of each respective individual subplot?
maybe try changing
fig.colorbar(aa)
to
fig.colorbar(aa,ax=axes[i,j])
Hope it helps!
This question already has answers here:
How do I change the plot size of a regplot in Seaborn?
(2 answers)
Closed 4 years ago.
I've tried as many solutions as I could find on here, but I'm not having much luck on this. I'm not sure if it's because some of my settings, but I am unable to reshape my Seaborn countplot. Here's my code where I plot the figure:
sns.set_style('whitegrid')
sns.set(font_scale=1.3)
sns.countplot(x=df['QuarterYear'], hue=df['Modifier'])
ax = plt.gca()
for p in ax.patches:
ax.text(p.get_x() + p.get_width()/2., p.get_height(), '%d' % int(p.get_height()),
fontsize=12, color='black', ha='center', va='bottom')
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
I am also editing the legend and labeling my countplot columns in the same block of code.
I am using Jupyter Notebook %inline. If anyone could explain what I am missing, that would be great. I've tried many, many variations of these solutions, to no avail.
How do I change the figure size for a seaborn plot?
How to make seaborn.heatmap larger (normal size)?
How do I change the plot size of a regplot in Seaborn?
Any help would be appreciated. Thank you for your time!
Have you tried:
fig = plt.gcf()
fig.set_size_inches( 16, 10)
This question already has answers here:
Rotate label text in seaborn factorplot
(10 answers)
Closed 6 years ago.
I would like to fix label problems in a seaborn graph, I have more than 30 items in the x axis. How to reduce the label dimension or may be rotate the graph?
import seaborn as sns
g = sns.factorplot(x="target", data=df3, kind="count",
palette="BuPu", size=6, aspect=1.5)
This will work if executed in a single cell in Jupyter:
g = sns.factorplot(x="target", data=df3, kind="count",
palette="BuPu", size=6, aspect=1.5)
g.set(xticks=np.arange(0, 40, 3)) # or however many you have
plt.xticks(rotation=90);
It will also work if executed as one block in Spyder.