Pretty simple, I want minor ticks on my subplot on the xaxis, but not the yaxis. I've tried all sorts (there seem to be hundreds of methods for ticks) but all seem to want me to specify the locations for the ticks, or use a TickLocator. I just want them on, and not to have to specify where (just like how the Major ticks work automatically).
Something like:
axis.set_minor_xticks_on()
or
axis.xaxis.set_minor_ticks()
or
axis.set_ticks(which='minor', True)
seems so simple but these don't work and I can't seem to find an equivalent. Surely there is one? I don't want labels on the minor ticks.
Using Python 3.5.2 and Matplotlib 1.5.3
I managed to achieve what I wanted to achieve with:
ax.minorticks_on()
ax.tick_params(axis='x', which='minor', direction='out')
Related
I really think my google skills and matplotlib documentation readings skills are failing me...but I do not seem to be able to find an answer.
I am applying some formatting to some plots I am doing:
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.xaxis.set_ticks_position('none')
ax.yaxis.set_ticks_position('none')
ax.grid(True, 'major', 'y', color='#D3D3D3')
ax.tick_params(axis='both', which='major', labelsize=12, labelcolor='#545454')
I would like this formatting to be applied to any future plots I do as well. Currently, as soon as I do a new plot, even of the same chart type and using the same data, the default formatting comes back.
I realise I can plot multiple charts in one figure, and I am doing this at times, but sometimes I only want to plot one chart at a time.
Is there a way to do this? Or is copy and paste my only solution?
Thanks for your time,
Ian.
Is there a way to turn of xticks and yticks using matplotlibrc or another matplotlib config method? The only way I see currently is to set the sizes of ticks and tick labels to zero. That seems an odd way, given that I can set_xticks(())
You can do this with tick_params
plt.tick_params(axis='both', which='both')
This is affecting both axis (other options are x or y). It also affects both major and minor ticks (other options are major or minor)
This will leave ticks around the outer edge, but not in the plot. If you want the edge ticks removed, you can add:
bottom='off'
top='off'
left='off'
right='off'
If you want to remove the labels, you'll want to turn these off
labelbottom='off'
labeltop='off'
labelleft='off'
labelright='off'
I am trying to plot a dataframe as hexbin but can't seem to get the xlabel and x-axis values to plot. The dataframe is as follows:
szen_df.xs('left', level='pos')
and the plot is as follows:
szen_df.xs('left', level='pos').plot(x='szen', y='lat', xlim=(0,90), ylim=(-90,90), kind='hexbin', colormap='Reds' )
with result:
I'm seeing this problem as well with python 2.7, pandas 0.16.2.dev, and ipython version 3.1.0.
Looking to the documentation for pandas.DataFrame.plot, the only reference to the x labels and ticks being invisible is in the sharex option. So, I manually set sharex=False, and poof, the xlabel and xticks come back.
Clearly this is a bug, but I hope this helps for the time being. I'll add these comments to the bug report that you've already started.
Looks like the same as the issue I had here: matplotlib scatterplot x axis labels
The workaround which worked was to set the axes explicitly. Just leaving this here for the future :)
Might be connected with https://github.com/pandas-dev/pandas/pull/12949 , Open as of now (6th of April 17)
I'm using Matplotlib in Python to plot simple x-y datasets. This produces nice-looking graphs, although when I "zoom in" too close on various sections of the plotted graph using the Figure View (which appears when you execute plt.show() ), the x-axis values change from standard number form (1050, 1060, 1070 etc.) to scientific form with exponential notation (e.g. 1, 1.5, 2.0 with the x-axis label given as +1.057e3).
I'd prefer my figures to retain the simple numbering of the axis, rather than using exponential form. Is there a way I can force Matplotlib to do this?
The formatting of tick labels is controlled by a Formatter object, which assuming you haven't done anything fancy will be a ScalerFormatterby default. This formatter will use a constant shift if the fractional change of the values visible is very small. To avoid this, simply turn it off:
plt.plot(arange(0,100,10) + 1000, arange(0,100,10))
ax = plt.gca()
ax.get_xaxis().get_major_formatter().set_useOffset(False)
plt.draw()
If you want to avoid scientific notation in general,
ax.get_xaxis().get_major_formatter().set_scientific(False)
Can control this with globally via the axes.formatter.useoffset rcparam.
You can use a simpler command to turn it off:
plt.ticklabel_format(useOffset=False)
You can use something like:
from matplotlib.ticker import ScalarFormatter, FormatStrFormatter
ax.xaxis.set_major_formatter(FormatStrFormatter('%.0f'))
Use the following command:
ax.ticklabel_format(useOffset=False, style='plain')
If you are using a subplot, you may experience the AttributeError: This method only works with the ScalarFormatter in which case you would add axis='y' like the below. You can change 'y' to the axis with the issues.
ax1.ticklabel_format(useOffset=False, style='plain', axis='y')
Source question and answer here. Note, the axis 'y' command use is hidden in the answer comments.
I have used below code before the graphs, and it worked seamless for me..
plt.ticklabel_format(style='plain')
Exactly I didn't want scientific numbers to be shown when I zoom in, and the following worked in my case too. I am using Lat/Lon in labeling where scientific form doesn't make sense.
plt.ticklabel_format(useOffset=False)
I'm using Matplotlib in Python to plot simple x-y datasets. This produces nice-looking graphs, although when I "zoom in" too close on various sections of the plotted graph using the Figure View (which appears when you execute plt.show() ), the x-axis values change from standard number form (1050, 1060, 1070 etc.) to scientific form with exponential notation (e.g. 1, 1.5, 2.0 with the x-axis label given as +1.057e3).
I'd prefer my figures to retain the simple numbering of the axis, rather than using exponential form. Is there a way I can force Matplotlib to do this?
The formatting of tick labels is controlled by a Formatter object, which assuming you haven't done anything fancy will be a ScalerFormatterby default. This formatter will use a constant shift if the fractional change of the values visible is very small. To avoid this, simply turn it off:
plt.plot(arange(0,100,10) + 1000, arange(0,100,10))
ax = plt.gca()
ax.get_xaxis().get_major_formatter().set_useOffset(False)
plt.draw()
If you want to avoid scientific notation in general,
ax.get_xaxis().get_major_formatter().set_scientific(False)
Can control this with globally via the axes.formatter.useoffset rcparam.
You can use a simpler command to turn it off:
plt.ticklabel_format(useOffset=False)
You can use something like:
from matplotlib.ticker import ScalarFormatter, FormatStrFormatter
ax.xaxis.set_major_formatter(FormatStrFormatter('%.0f'))
Use the following command:
ax.ticklabel_format(useOffset=False, style='plain')
If you are using a subplot, you may experience the AttributeError: This method only works with the ScalarFormatter in which case you would add axis='y' like the below. You can change 'y' to the axis with the issues.
ax1.ticklabel_format(useOffset=False, style='plain', axis='y')
Source question and answer here. Note, the axis 'y' command use is hidden in the answer comments.
I have used below code before the graphs, and it worked seamless for me..
plt.ticklabel_format(style='plain')
Exactly I didn't want scientific numbers to be shown when I zoom in, and the following worked in my case too. I am using Lat/Lon in labeling where scientific form doesn't make sense.
plt.ticklabel_format(useOffset=False)