Matplotlib log colorbar minor ticks disappear when range is less than a decade
Date : March 29 2020, 07:55 AM
wish helps you Matplotlib colorbars don't seem to do minor ticks in log scale. Using the method in this answer works, though it's a bit inconvenient - one day this will be automatic, but for now you have to organise the minor tick values by hand (np.arange(2, 10)/10. in this case, but you'd have to append np.arange(2, 10) if your values went up to 10) import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
# fill grid
x = np.linspace(1,10,10)
y = np.linspace(1,10,10)
X, Y = np.meshgrid(x,y)
# Z = np.abs(X + Y)
Z = np.abs(X/10 + Y/10)
# plot
f, ax = plt.subplots()
p = plt.pcolormesh(X, Y, Z, norm=LogNorm(), vmin=2e-1, vmax=1)
cb = plt.colorbar(p, ax=ax)
# cb.ax.minorticks_on()
# We need to nomalize the tick locations so that they're in the range from 0-1...
minorticks = p.norm(np.arange(2, 10)/10.)
cb.ax.yaxis.set_ticks(minorticks, minor=True)
plt.show()
|
Zedgraph - last minor ticks disappear
Tag : chash , By : noboruwatanabe
Date : March 29 2020, 07:55 AM
it should still fix some issue Looks like this an issue in the Axis.DrawMinorTics method. Axis values are doubles, and XDate uses lets say days as its base unit, 2011,2,5 and 2011,2,5,0,0,5 are converted to doubles as 40579.0 and 40579.000057870522 var start = new XDate(2011, 2, 5);
pane.XAxis.Scale.Min = new XDate(2011, 2, 5, 0, 0, 0, 0) - start;
pane.XAxis.Scale.Max = new XDate(2011, 2, 5, 0, 0, 5, 0) - start;
|
x-ticks disappear when plotting on subplots sharing x-axis
Tag : python , By : user135518
Date : November 09 2020, 03:01 PM
help you fix your problem There are two options. One is based on the answer to this question: matplotlib - pandas - No xlabel and xticks for twinx axes in subploted figures which is to reverse the order of plotting. First plot to the two subplots, then create the twin axes for both. import matplotlib.pyplot as plt
import pandas as pd
fig, axes = plt.subplots(nrows=2, ncols=1)
data=pd.DataFrame([[1,2,3],[2,3,4],[3,2,4]])
ax=axes[0]
y=pd.DataFrame(data.iloc[:,0]-data.iloc[:,1])
data.plot(ax=ax)
ax3=axes[1]
y=pd.DataFrame(data.iloc[:,0]-data.iloc[:,1])
data.plot(ax=ax3)
ax2=ax.twinx()
ax2.plot(y.values)
ax4=ax3.twinx()
ax4.plot(y.values)
plt.show()
[t.set_visible(True) for t in ax.get_xticklabels()]
import matplotlib.pyplot as plt
import pandas as pd
fig, axes = plt.subplots(nrows=2, ncols=1)
data=pd.DataFrame([[1,2,3],[2,3,4],[3,2,4]])
ax=axes[0]
y=pd.DataFrame(data.iloc[:,0]-data.iloc[:,1])
ax2=ax.twinx()
data.plot(ax=ax)
ax2.plot(y.values)
ax3=axes[1]
y=pd.DataFrame(data.iloc[:,0]-data.iloc[:,1])
ax4=ax3.twinx()
data.plot(ax=ax3)
ax4.plot(y.values)
[t.set_visible(True) for t in ax.get_xticklabels()]
plt.show()
|
matplotlib colorbar minor ticks color and number of minor ticks
Tag : python , By : fedorafennec
Date : March 29 2020, 07:55 AM
Hope that helps I have a matplotlib (v2.1.1) plot that includes a colorbar. When plotted on a figure with a white background, I get a colorbar as shown in one of the attached images. That is fine (though I'd love to know how to set the number of minor ticks). , You may use rcParams to set the required colors. import matplotlib.pyplot as plt
background = 0
if background == 0:
back_color='black'
fore_color='white'
else:
back_color='white'
fore_color='black'
plt.rcParams["text.color"] = fore_color
plt.rcParams["axes.labelcolor"] = fore_color
plt.rcParams["xtick.color"] = fore_color
plt.rcParams["ytick.color"] = fore_color
fig, ax = plt.subplots()
fig.patch.set_facecolor(back_color)
im = ax.imshow([[1e5,2e5],[0.1e5,1e5]])
ax.axis( 'off' ) # don't show the axes ticks/lines/etc. associated with the image
cb = plt.colorbar(im)
cb.formatter.set_scientific(True)
cb.formatter.set_powerlimits((0,0))
cb.ax.minorticks_on()
cb.update_ticks()
plt.show()
import matplotlib.pyplot as plt
background = 0
if background == 0:
plt.style.use("dark_background")
fig, ax = plt.subplots()
im = ax.imshow([[1e5,2e5],[0.1e5,1e5]])
ax.axis( 'off' )
cb = plt.colorbar(im)
cb.formatter.set_scientific(True)
cb.formatter.set_powerlimits((0,0))
cb.ax.minorticks_on()
cb.update_ticks()
plt.show()
|
Matplotlib won't show minor ticks when using subplots
Tag : python , By : user122937
Date : March 29 2020, 07:55 AM
will help you With pyplot the danger is that you loose track of which one the current axes is that a command like plt.minorticks_on() operates on. Hence it would be beneficial to use the respective methods of the axes you're working with: ax1.minorticks_on()
ax2.minorticks_on()
|