How can I create a figure with optimal resolution for printing?
<p>I'm rather fond of <a href="https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Logistic_Bifurcation_map_High_Resolution.png/800px-Logistic_Bifurcation_map_High_Resolution.png" rel="nofollow">The Logistic Map' Period Doubling Bifurcation</a> and would like to print it on a canvas.</p>

<p>I can create the plot in python, but need some help preparing figure properties so that it has suitable resolution to be printed.  My code right ow produces some jagged lines.</p>

<p>Here is my code:</p>

<p>import numpy as np
import matplotlib.pyplot as plt</p>

<pre><code># overall image properties
width, height, dpi = 2560, 1440, 96
picture_background = 'white'
aspect_ratio = width / height


plt.close('all')
R = np.linspace(3.5,4,5001)

fig = plt.figure(figsize=(width / dpi, height / dpi), frameon=False)
ylim = -0.1,1.1
ax = plt.Axes(fig, [0, 0, 1, 1], xlim = (3.4,4))
ax.set_axis_off()
fig.add_axes(ax)

for r in R:

    x = np.zeros(5001)

    x[0] = 0.1

    for i in range(1,len(x)):

        x[i] = r*x[i-1]*(1-x[i-1])


    ax.plot(r*np.ones(2500),x[-2500:],marker = '.', markersize= 0.01,color = 'grey', linestyle = 'none')

plt.show()  
plt.savefig('figure.eps', dpi=dpi, bbox_inches=0, pad_inches=0, facecolor=picture_background)
</code></pre>

<p>Here is what the code produces:</p>

<p><a href="http://i.stack.imgur.com/kqm6B.png" rel="nofollow"><img src="http://i.stack.imgur.com/kqm6B.png" alt="enter image description here"></a></p>

<p>As you can see, some of the lines to the far left of the plot are rather jagged.</p>

<p>How can I create this figure so that the resolution is suitable to be printed on a variety of frame dimensions?</p>

<p>I think the source of the jaggies is underlying pixel size + that you are drawing this using very small 'point' markers.  The pixels that the line are going through are getting fully saturated so you get the 'jaggy'.</p>

<p>A somewhat better way to plot this data is to do the binning ahead of time and then have mpl plot a heat map:</p>

<pre><code>import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
plt.ion()

width, height, dpi = 2560 / 2, 1440 / 2, 96  # cut to so SO will let me upload result

aspect_ratio = width / height

fig, ax = plt.subplots(figsize=(width / dpi, height / dpi), frameon=False,
                       tight_layout=True)
ylim = -0.1, 1.1
ax.axis('off')


# make heatmap at double resolution
accumulator = np.zeros((height, width), dtype=np.uint64)

burn_in_count = 25000
N = 25000

R = np.linspace(3.5, 4, width)
x = 0.1 * np.ones_like(R)
row_indx = np.arange(len(R), dtype='uint')
# do all of the r values in parallel
for j in range(burn_in_count):
    x = R * x * (1 - x)

for j in range(N):
    x = R * x * (1 - x)
    col_indx = (height * x).astype('int')
    accumulator[col_indx, row_indx] += 1

im = ax.imshow(accumulator, cmap='gray_r',
               norm=mcolors.LogNorm(), interpolation='none')
</code></pre>

<p><a href="http://i.stack.imgur.com/uii6n.png" rel="nofollow"><img src="http://i.stack.imgur.com/uii6n.png" alt="log scaled logistic map"></a></p>

<p>Note that this is log-scaled, if you just want to see what pixels are hit</p>

<p>use  </p>

<pre><code>im = ax.imshow(accumulator&gt;0, cmap='gray_r', interpolation='nearest')
</code></pre>

<p><a href="http://i.stack.imgur.com/TroiA.png" rel="nofollow"><img src="http://i.stack.imgur.com/TroiA.png" alt="logistic map &#39;hits&#39;"></a></p>

<p>but these still have issues of the jaggies and (possibly worse) sometimes the narrow lines get aliased out.</p>

<p>This is the sort of problem that <a href="https://github.com/bokeh/datashader" rel="nofollow">datashader</a> or <a href="https://github.com/bokeh/datashader" rel="nofollow">rasterized scatter</a> is intended to solve by re-binning the data at draw time in an intelligent way (<a href="https://github.com/bokeh/datashader/pull/200" rel="nofollow">see this PR for a prototype datashader/mpl integartion</a>).  Both of those are still prototype/proof-of-concept, but usable.</p>

<p><a href="http://matplotlib.org/examples/event_handling/viewlims.html" rel="nofollow">http://matplotlib.org/examples/event_handling/viewlims.html</a> which re-compute the Mandelbrot set on zoom might also be of interest to you. </p>

python matplotlib figure