figure

matplotlib savefig in jpeg format

自古美人都是妖i 提交于 2019-11-26 09:44:18
问题 I am using matplotlib (within pylab) to display figures. And I want to save them in .jpg format. When I simply use the savefig command with jpg extension this returns : ValueError: Format \"jpg\" is not supported. Supported formats: emf, eps, pdf, png, ps, raw, rgba, svg, svgz. Is there a way to perform this ? 回答1: 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(

Python Matplotlib figure title overlaps axes label when using twiny

五迷三道 提交于 2019-11-26 07:59:09
问题 I am trying to plot two separate quantities on the same graph using twiny as follows: fig = figure() ax = fig.add_subplot(111) ax.plot(T, r, \'b-\', T, R, \'r-\', T, r_geo, \'g-\') ax.set_yscale(\'log\') ax.annotate(\'Approx. sea level\', xy=(Planet.T_day*1.3,(Planet.R)/1000), xytext=(Planet.T_day*1.3, Planet.R/1000)) ax.annotate(\'Geostat. orbit\', xy=(Planet.T_day*1.3, r_geo[0]), xytext=(Planet.T_day*1.3, r_geo[0])) ax.set_xlabel(\'Rotational period (hrs)\') ax.set_ylabel(\'Orbital radius

Matplotlib (pyplot) savefig outputs blank image

﹥>﹥吖頭↗ 提交于 2019-11-26 01:53:09
问题 I am trying to save plots I make using matplotlib; however, the images are saving blank. Here is my code: plt.subplot(121) plt.imshow(dataStack, cmap=mpl.cm.bone) plt.subplot(122) y = copy.deepcopy(tumorStack) y = np.ma.masked_where(y == 0, y) plt.imshow(dataStack, cmap=mpl.cm.bone) plt.imshow(y, cmap=mpl.cm.jet_r, interpolation=\'nearest\') if T0 is not None: plt.subplot(123) plt.imshow(T0, cmap=mpl.cm.bone) #plt.subplot(124) #Autozoom #else: #plt.subplot(124) #Autozoom plt.show() plt.draw()

In Matplotlib, what does the argument mean in fig.add_subplot(111)?

▼魔方 西西 提交于 2019-11-26 00:38:56
问题 Sometimes I come across code such as this: import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [1, 4, 9, 16, 25] fig = plt.figure() fig.add_subplot(111) plt.scatter(x, y) plt.show() Which produces: I\'ve been reading the documentation like crazy but I can\'t find an explanation for the 111 . sometimes I see a 212 . What does the argument of fig.add_subplot() mean? 回答1: These are subplot grid parameters encoded as a single integer. For example, "111" means "1x1 grid, first subplot" and

How to prevent numbers being changed to exponential form in Python matplotlib figure

南楼画角 提交于 2019-11-26 00:33:46
问题 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