gca and latest version of Matplotlib
You can try: fig = plt.figure() ax = fig.add_subplot(projection=’3d’)
You can try: fig = plt.figure() ax = fig.add_subplot(projection=’3d’)
You can finish the corresponding (matplotlib) line with a semicolon ;
Below I provide functions to convert a colored line to a black line with unique style. My quick test showed that after 7 lines, the colors repeated. If this is not the case (and I made a mistake), then a minor adjustment is needed for the “constant” COLORMAP in the provided routine. Here’s the routine … Read more
A simpler way is to use the set_tick_params function of axis objects: ax.xaxis.set_tick_params(width=5) ax.yaxis.set_tick_params(width=5) Doing it this way means you can change this on a per-axis basis with out worrying about global state and with out making any assumptions about the internal structure of mpl objects. If you want to set this for all the … Read more
cb.set_label(“Foo”, labelpad=-1) Negative labelpad values will move closer to the bar, positive away.
use the align_yaxis() function: import numpy as np import matplotlib.pyplot as plt def align_yaxis(ax1, v1, ax2, v2): “””adjust ax2 ylimit so that v2 in ax2 is aligned to v1 in ax1″”” _, y1 = ax1.transData.transform((0, v1)) _, y2 = ax2.transData.transform((0, v2)) inv = ax2.transData.inverted() _, dy = inv.transform((0, 0)) – inv.transform((0, y1-y2)) miny, maxy = … Read more
You can save an image as ‘png’ and use the python imaging library (PIL) to convert this file to ‘jpg’: import Image import matplotlib.pyplot as plt plt.plot(range(10)) plt.savefig(‘testplot.png’) Image.open(‘testplot.png’).save(‘testplot.jpg’,’JPEG’) The original: The JPEG image:
You can do plot(x,y,marker=”o”,markevery=5) to mark every fifth point, but I don’t think there is any built-in support for setting marks at even intervals. You could decide on the x locations where you want the marks, use e.g. numpy.searchsorted to find which data points the locations fall between, and then interpolate between the neighboring points … Read more
In the legend command you can use the scatterpoints option: ax.legend(loc=0, scatterpoints = 1) For a normal plot, it is the option numpoints. Here you can find more information about the keyword arguments for the legend: http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.legend
Use the horizontalalignment (which can be shortened as ha) option to the annotate call: text_object = plt.annotate(label, xy=(x_values[i], y_values[i]), ha=”center”)