Is it just me or are some gridlines thicker than others?
If you look at the top plot, the vertical lines at 3.5 and 4 seem thicker than the other vertical lines. And the lines at 12.5 and 13.5 seem thicker than the other horizontal lines. In the plot below, you see the same for vertical 10 and horizontal 20 and 25. You can see this inconsistency in any other plot.
Is this just an optical illusion? If not, how can I make them consistent?
Edit: Taking a screenshot of the graphs changes the perceived thick lines, some previously thick lines become normal and some new lines get thicker. This leads me to believe this is just an optical illusion. Baffling nonetheless.
Edit 2: Here's an indepth look. This is from plotly's documentation page itself. You can see in the image the line in the lower plot is two pixels long. (The pixel reading is that of the line to the immediate left of it)
Edit 3: Here's more screenshots of my chrome browser and from my android phone. These too show inconsistencies in thickness.
Android-
Edit 4: Resizing the window changes the thickness of the lines, makes some thicker whilst making others thinner.
Also, checked plotly docs on a mac. Lines were consistent with same thickness.
This is definitely something in your local environment.
I open the plotly page you linked above (in Chrome), take a screenshot and paste into mspaint (so direct bitmap paste - no compression) and can see that all gridlines are 1px wide, except for the
axes, which are 2px.
I'm almost 100% certain that what you're seeing here is an aliasing effect caused by the image compression. As a test - try exporting the charts as BMP, or even a higher resolution jpg/png, and I'm fairly confident you won't see this.
Related
**Note: My code is at the end of the question.
I want to recreate this chart in matplotlib:
I have come a long way of making something similar but I am stuck in the last part, which is to zoom in the plot to remove all the white space. So basically, I want to zoom in to the red box:
Note that the grid will be removed on the actual chart. Displaying it now to explain what I would like done.
Is that possible? My code is here:
https://github.com/Curbal-Data-Labs/Matplotlib-Labs/blob/master/Polar%20charts/Polar%20bar%20chart.ipynb
OK, I've got some data that I'm plotting with matplotlib in python 3.x (it's basically just a csv file with x and y data)
The graph plots fine, except that it ends up with weird bands in it where the spacing between the bars seems to have broken down:
I know it's not a problem with the data because I ran a test in excel, and got interesting patterns there as well (though in different places)
Please can anybody tell me whether 1) this is something that is already known about, and 2) there is a way of correcting it?
This is a problem of stamping in raster images like bmp or png. The structure you want to show (in this case vertical lines) shows features the size of which are on the same order of magnitude than the raster grid (the pixels of the image). This will inevitably lead to distotions.
The option you have is to increase dpi, such that the lines have more pixels to be placed on.
I'm plotting two lines, one solid, one dashed. At the initial zoom the lines appear as defined. However, when zooming into the plot the dashed line becomes solid. The pictures below illustrate the problem. Here is the code that defines the lines:
turbidity_stn3_plot1 = f.line(x='Datetime',y='Turbidity', y_range_name='default', color='olive',line_color='black', line_dash=[1,10], line_width=1, source=turbidity_stn_03_plot_01_source)
turbidity_stn1_plot1 = f.line(x='Datetime',y='Turbidity', y_range_name='default', color='olive',line_color='black', line_dash='solid', source=turbidity_stn_01_plot_01_source)
I already tried different 'line_dash' values, like 'dashed' and 'dotted' with the same result.
I noticed that, when increasing the distance between dashes (e.g. 'line_dash=[1,20]'), the closer I can zoom in before the line turns solid.
Does anybody know why this is and how to avoid it?
Should I report this as a bug on Bokeh Github?
This is a result of browser-dependent behavior of HTML canvas implementations. There is nothing that the Bokeh project can do about it (which is why the GH issue was eventually closed). If you are working in regimes where this issue shows up, the only alternative is to use other visual properties, e.g. width or color, instead of dashing.
I plot rather complex data with matplotlib's imshow(), so I prefer to first visually inspect if it is all right, before saving. So I usually call plt.show(), see if it is fine, and then manually save it with a GUI dialog in the show() window. And everything was always fine, but recently I started getting a weird thing. When I save the figure I get a very wrong picture, though it looks perfectly fine in the matplotlib's interactive window.
If I zoom to a specific location and then save what I see, I get a fine figure.
So, this is the correct one (a small area of the picture, saved with zooming first):
And this one is a zoom into approximately the same area of the figure, after I saved it all:
For some reason pixels in the second one are much bigger! That is vary bad for me - as you can see, it looses a lot of details in there.
Unfortunately, my code is quite complicated and I wasn't able to reproduce it with some randomly generated data. This problem appeared after I started to plot two triangles of the picture separately: I read my two huge data files with np.loadtxt(), get np.triu(data1) and np.tril(data2), mask zeroes, NAs, -inf and +inf and then plot them on the same axes with plt.imshow(data, interpolation='none', origin='lower', extent=extent). I do lot's of other different things to make it nicer, but I guess it doesn't matter, because it all worked like a charm before.
Please, let me know, if you need to know anything else specific from my code, that could be relevant to this problem.
When you save a figure in png/jpg you are forced to rasterize it, convert it to a finite number of pixels. If you want to keep the full resolution, you have a few options:
Use a very high dpi parameter, like 900. Saving the plot will be slow, and many image viewers will take some time to open it, but the information is there and you can always crop it.
Save the image data, the exact numbers you used to make the plot. Whenever you need to inspect it, load it in Matplotlib in interactive mode, navigate to your desired corner, and save it.
Use SVG: it is a vector graphics format, so you are not limited to pixels.
Here is how to use SVG:
import matplotlib
matplotlib.use('SVG')
import matplotlib.pyplot as plt
# Generate the image
plt.imshow(image, interpolation='none')
plt.savefig('output_image')
Edit:
To save a true SVG you need to use the SVG backend from the beginning, which is unfortunately, incompatible with interactive mode. Some backends, like GTKCairo seem to allow both, but the result is still rasterized, not a true SVG.
This may be a bug in matplotlib, at least, to the best of my knowledge, it is not documented.
I am trying to minimize margins around a 1X2 figure, a figure which are two stacked subplots. I searched a lot and came up with commands like:
self.figure.subplots_adjust(left=0.01, bottom=0.01, top=0.99, right=0.99)
Which leaves a large gap on top and between the subplots. Playing with these parameters, much less understanding them was tough (things like ValueError: bottom cannot be >= top)
My questions :
What is the command to completely minimize the margins?
What do these numbers mean, and what coordinate system does this follow (the non-standard percent thing and origin point of this coordinate system)? What are the special rules on top of this coordinate system?
Where is the exact point this command needs to be called? From experiment, I figured out it works after you create subplots. What if you need to call it repeatedly after you resize a window and need to resize the figure to fit inside?
What are the other methods of adjusting layouts, especially for a single subplot?
They're in figure coordinates: http://matplotlib.sourceforge.net/users/transforms_tutorial.html
To remove gaps between subplots, use the wspace and hspace keywords to subplots_adjust.
If you want to have things adjusted automatically, have a look at tight_layout
Gridspec: http://matplotlib.sourceforge.net/users/gridspec.html