J W
J W

Reputation: 637

Hatching frequency on plots

Suppose I have the following script that produces a plot (as shown below) where some datapoints have hatching. At DPI = 200, the hatching frequency (space between dots) is good, but if I want to increase the resolution of the plot (DPI = 600 for example), the dots become very fine. Is there a way to set the gap between dots? Thanks in advance.

import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.basemap import Basemap


Sig = np.random.rand(50,50)
Sig = np.ma.masked_greater(Sig, 0.25)

f, ax1 = plt.subplots(1,1)

ax1.pcolor(np.linspace(0,90,50),np.linspace(0,50,50),Sig, hatch=".",alpha=0)

fig = plt.gcf()
fig.set_size_inches(8, 8)
fig.savefig('Trial.png',bbox_inches='tight', dpi=200)

enter image description here

Upvotes: 3

Views: 2462

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339430

There is no way to accurately control the spacing between hatch patterns. You do have the option to increase the hatch density though. Instead of hatch = "." you can add the symbol more often, hatch="..."; this will produce a denser pattern.

enter image description here

The above figure has been produced with standard dpi of 100. Changing the dpi to 300 gives the following image:

enter image description here

As can be seen the issue of a changed hatch density for different dpi is not there anymore; it has been brought up in this issue and afterwards been fixed. The solution is thus to update to the newest matplotlib version.

Upvotes: 8

Related Questions