I am currently working on a data visualization web application with DashPlotly. My goal is to create "stylized" dashboards with DBC. I have a problem with the size of the plotly figures, they are "too zoomed". Indeed, the ideal rendering for me would be the rendering provided with the browser zoomed out to 67%. I attach a GIF to illustrate my point.
I wonder then if it is possible to have a less coarse rendering of plotly figures when the browser is zoomed to 100% ?
I specify that I work on a small screen (laptop 15") and I would like the rendering of the figures to be the same for all types of screens.
For this example I applied a css zoom directly on the DBC card but this is not a viable solution in the long run.
If someone has already encountered a similar problem, I'm interested ;)
Have a good day
I finally found a solution to my problem. What happens when you zoom out with the browser is that the font size of the elements in the figure decreases. So I simply reduced the font size of my plotly figures...
fig.update_layout(
font=dict(
size=12
)
)
Related
I'm using PyQt5 (5.13.1) in python 3.7.4
I'm using macos for now (10.14.5) on an imac with one retina display and one non-retina display
I'm plotting a graph using matplotlib inside a scroll area
I've encountered a strange issue. I do not know if posting any code would be useful, but if you think some specific code will help, please let me know what code and i'll post.
here is the weird issue:
On the non-retina monitor, everything works fine. I can scroll up and down and see my graph and other scroll content. When I save the scroll area widget to an image, it is nice. All content is there. But, of course the resolution isn't great because it's the non-retina display.
On the retina monitor, as I scroll down, the bottom of the graph starts to disappear. and more disappears the more I scroll. The saved image looks exactly the same: whatever has disappeared on the screen is actually missing in the image (even though saving the whole scroll area should not do that, and in fact this error does not happen on the non-retina monitor or for content on the retina monitor that is not the matplolib graph. So, just to be clear, the issue is that matplotlib graphs seem to disappear at they are scrolled on my retina monitor.
As you can see from the images, the part of the graph that disappears starts at the bottom, not the part that is no longer visible because of scrolling.
scroll window on non-retina display. no problems
after dragging window to retina display, the bottom of the figure (from the x-axis) begins to disappear
So, does anyone know about this matplotlib issue? is there a setting that I seed to implement?
I am using bokeh for plotting. With my current settings, bokeh shows some text and lines kind of blurred (anti-aliased?). This is not really noticeable on my monitor, but on some projectors, especially when doing screenshots and inserting them into presentations, it looks weird.
As requested, a minimum working example:
from bokeh.plotting import figure, show
p = figure(plot_width=1000, plot_height=600,
title="TestTitle", x_axis_label = "Length [cm]", y_axis_label="Height [m]")
p.xaxis.axis_label_text_font_style = "normal"
p.xaxis.axis_label_text_font_size = "12pt"
show(p)
I am using Windows 7 and tried this in the current versions of Chrome and IE. Python 3.6, bokeh version 0.13.0. The first image is taken from the example, the second is taken from my real code:
I tried different figure sizes, but the problem persists - maybe I am trying the wrong ones? Anything I can do about this, except simply trying different sizes until something "works"? Setting px instead of pts seems to make it worse...
Regarding the text, it is rendered on to a raster HTML canvas, and the details of how this is done are entirely dependent on the browser canvas implementation. (FWIW things look better on any browser on OSX than the above image.) There's not anything we can to change how a specific browser renders text, and not much I can suggest except to make much bigger canvas sizes if you need to show something extremely magnified.
Regarding the aliasing of the axes and tick marks, I can't reproduce anything like that on any OSX browser (Safari, FF, or Chrome). It definitely appears to be a Windows-specific issue. It's possible there are issues that could be addressed, e.g a different HiDPI setting, or half-pixel offsets, but it would take investigation to try and determine what can be done. A Github issue with details would be appropriate, but I can't speculate when it might be addressed (we are under-resourced and no core contributors are regular windows users).
I've been learning dash and plot.ly to make some data viz with python. It's been great so far, but one nagging problem is that scattergeo plots don't utilize their space well.
I have the scattergeo plot sitting in a width:100% content div and it shares the total width 60/40 with another plot. But the space that the scattergeo uses is much less than the space allotted. Below is an image where the scattergeo's div has a border around it showing how inefficiently it uses its space.
Is there any way to increase this plot type's space utilization within its div element?
I had the same problem, the solution I found was to use update_layout in this way:
figure = offline.plot(go.Figure(data=data, layout=layout).update_layout(height=300, margin={"r":0,"t":25,"l":0,"b":0}), output_type='div', show_link=False)
I just can't seem to grok plotting library documentation!
I have spent ages looking at the documentation for Bokeh and I can't figure out how to turn on the grid for this example: http://docs.bokeh.org/en/latest/docs/gallery/image.html
This is despite the fact that the thumbnail for this example actually does show the grid as seen here: http://docs.bokeh.org/en/latest/
I have tried looking at other gallery examples which do have grids visible but alot of them make no mention of grid.
Any ideas? Thanks!
I am afraid you have uncovered a deficiency in the current version (0.8.1) of Bokeh. The Image glyph was move to the underlay render level, which is the same as the grid. If you pan the plot, you will see the grid is actually on, the image is just on top of it. This might OK sometimes, but there is unfortunately not any way to change the render level back lower if that is what is desired. I've made an issue you can track:
https://github.com/bokeh/bokeh/issues/2040
This will be fixed in the 0.9 release.
I'm preparing some plots for a scientific paper, which need to be wide and short in order to fit into the page limit. However, when I save them as pdf, the x axis labels are missing, because (I think) they're outside the bounding box.
Putting the following into an iPython notebook reproduces the problem.
%pylab inline
pylab.rcParams['figure.figsize'] = (8.0, 2.0)
plot([1,5,2,4,6,2,1])
xlabel("$x$")
ylabel("$y$")
savefig("test.pdf")
The resulting pdf file looks like this:
How can I change the bounding box of the pdf file? Ideally I'd like a solution that "does it properly", i.e. automatically adjusts the size so that everything fits neatly, including getting rid of that unnecessary space to the left and right - but I'm in a hurry, so I'll settle for any way to change the bounding box, and I'll guess numbers until it looks right if I have to.
After a spot of Googling, I found an answer: you can give bbox_inches='tight' to the savefig command and it will automatically adjust the bounding box to the size of the contents:
%pylab inline
pylab.rcParams['figure.figsize'] = (8.0, 2.0)
plot([1,5,2,4,6,2,1])
xlabel("$x$")
ylabel("$y$")
savefig("test.pdf",bbox_inches='tight')
Those are some tight inches, I guess.
Note that this is slightly different from Ffisegydd's answer, since it adjusts the bounding box to the plot, rather than changing the plot to fit the bounding box. (But both are fine for my purposes.)
You can use plt.tight_layout() to have matplotlib adjust the layout of your plot. tight_layout() will automatically adjust the dimensions, and can also be used when you have (for example) overlapping labels/ticks/etc.
%pylab inline
pylab.rcParams['figure.figsize'] = (8.0, 2.0)
plot([1,5,2,4,6,2,1])
xlabel("$x$")
ylabel("$y$")
tight_layout()
savefig("test.pdf")
Here is a .png of the output (can't upload pdfs to SO but I've checked it and it works the same way for a pdf).
If you are preparing the plot for a scientific paper, I suggest to do the 'clipping' by yourself,
using
plt.subplots_adjust(left,right,bottom,top,..)
after the creation of the figure and before saving it. If you are running from an ipython console you can also call subplots_adjust after the generation of the figure, and tune the margins by trial and error. Some backends (I think at least the Qt backend) also expose a GUI for this feature.
Doing this by hand takes time, but most times provides a more precise result, especially with Latex rendering in my experience.
This is the only option whenever you have to stack vertically or horizontally two figures (with a package like subfigure for example), as tight_layout will not guarantee the same margins in the two figures, and the axis will result misaligned in the paper.
This is a nice link on using matplotlib for publications, covering for example how to set the figure width to match the journal column width.